[76] in java-interest
Re: problem with synchronize( )
daemon@ATHENA.MIT.EDU (Arthur van Hoff)
Wed May 10 16:56:31 1995
Date: Wed, 10 May 1995 09:12:57 -0700
From: Arthur.Vanhoff@Eng.Sun.COM (Arthur van Hoff)
To: java-interest@java.Eng.Sun.COM
Hi Suresh,
> In the following, the first synchronize() statement completely confuses
> javac, while the second one works. Why is this ? To work around this
> problem, I'm having to use an elaborate set of lock()s and unlock()s. Also
> it would be nice if synchronize() accepted multiple objects/classes for
> locking in a single call:
>
> int i;
> int j[] = new int[5];
> .....
> synchronize(i)
> { i = 3;
> ......
> }
> ......
> synchronize(j)
> { j[1] = 3;
> .....
> }
The problem is that you can only synchronize on objects. Unfortunately
integers aren't objects so you can't synchronize on them. It is actually
very unusual that you have to use the synchronize statement, it is often
enough to use the synchronize modifier on the methods you are in.
Have fun,
Arthur van Hoff (avh@eng.sun.com)
http://java.sun.com/people/avh/
Sun Microsystems Inc, M/S UPAL02-301,
100 Hamilton Avenue, Palo Alto CA 94301, USA
Tel: +1 415 473 7242, Fax: +1 415 473 7104
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com