[77] in java-interest

home help back first fref pref prev next nref lref last post

Re: problem with synchronize( )

daemon@ATHENA.MIT.EDU (Suresh K Jois)
Wed May 10 17:12:35 1995

Date: Wed, 10 May 95 12:41:50 -0800
From: suresh@internet.net (Suresh K Jois)
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 ?
>> 
>> 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.

If  I understand correctly, synchronize methods serialize access only to
the instance variables of their own class/object, and hence if I want to
serialize access to instance vars of other classes, I have to explicitly use
synchronize.

Is this correct ? BTW, if ints are not classes nor objects, what are they ?
I thought everything in Java was a class or an object.

- Suresh
-----------------------------------------------------------------
Suresh K Jois. CyberSpace Gypsy. Virtual Spaces Architect.
Email: suresh@internet.net (Work)  sujo@netcom.com (Home)
WWW:http://www.internet.net
Traceroute: ->Informix->SiliconGraphics->Sun Microsystems
            ->Home Shopping Channel Inc/Internet Shopping Network
-----------------------------------------------------------------

-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post