[gclist] Garbage collection and XML

Bob Kerns Bob.Kerns@brightware.com
Wed, 7 Mar 2001 09:42:07 -0800


String foo = dosomething();
synchronized (foo) {
  ....
}

As he said, every object can be used for synchronization. Synchronized
methods effectively wrap

synchronized (this) {
  ...
}

around the body of the method, but you can synchronize on any object at any
time.

-----Original Message-----
From: Fergus Henderson [mailto:fjh@cs.mu.oz.au]
Sent: Wednesday, March 07, 2001 9:36 AM
To: Boehm, Hans
Cc: 'Bill Foote'; Richard A. O'Keefe; chase@world.std.com;
gclist@iecc.com; icis-developers@bbn.com
Subject: Re: [gclist] Garbage collection and XML


On 07-Mar-2001, Boehm, Hans <hans_boehm@hp.com> wrote:
> You could presumably also synchronize on the strings, effectively turning
> them into locks.  In that case sharing might result in unexpected lock
> contention or deadlock.  The fact that every object can be used for
> synchronization means that in some sense nothing is immutable.

How would you synchronize on the strings?
The java.lang.String class is declared `final', so you can't
inherit from it, and AFAIK there are no synchronized methods
in java.lang.String.

-- 
Fergus Henderson <fjh@cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.