[concurrency-interest] Re: SynchronizedLong vs. other locks

Aleksey Gureev spyromus at noizeramp.com
Fri Jul 8 05:39:09 EDT 2005


Actually, it is already class-wide, sorry, but anyway, any help from
SynchronizedLong?

Aleksey Gureev
Noizeramp Creative Group
http://www.noizeramp.com/

On Fri, 2005-07-08 at 12:37 +0300, Aleksey Gureev wrote:
> Hi,
> 
> I have a following piece of code:
> 
> ---
>     private static synchronized long getTomorrowTime()
>     {
>         final long current = System.currentTimeMillis();
>         if (current > tomorrow)
>         {
>             GregorianCalendar cal = new GregorianCalendar();
>             cal.add(Calendar.DATE, 1);
>             cal.set(Calendar.HOUR_OF_DAY, 0);
>             cal.set(Calendar.MINUTE, 0);
>             cal.set(Calendar.SECOND, 0);
>             cal.set(Calendar.MILLISECOND, 0);
>             tomorrow = cal.getTimeInMillis();
>         }
> 
>         return tomorrow;
>     }
> ---
> 
> "tomorrow" is static. It's obvious that the instance synchronization is
> not really what's necessary because the other objects of this class can
> still introduce race conditions. My question is can SynchronizedLong
> help me somehow or it's better to replace instance locking with
> class-wide locking?
> 
> Thank you,
> 
> Aleksey Gureev
> Noizeramp Creative Group
> http://www.noizeramp.com/
> 



More information about the Concurrency-interest mailing list