Re: Running concurrent Mulithreaded Application
Re: Running concurrent Mulithreaded Application
- Subject: Re: Running concurrent Mulithreaded Application
- From: LD <email@hidden>
- Date: Thu, 1 Sep 2005 02:55:10 +1000
Hi there,
On 01/09/2005, at 2:32 AM, Mike Schrag wrote:
On Aug 31, 2005, at 12:19 PM, LD wrote:
Unfortunately, Java's synchronized keyword lends itself to abuse
unless you understand what it's doing. You need to understand that
the synchronized methods block all access to the instance until
that lone thread has left the building! Doing this on your
Application instance is probably less than desirable.
Just to clarify -- synchronized blocks and methods block access to
all other synchronized blocks that share the same monitor lock, not
all methods on the instance.
Only true if the monitor lock is not implied. i.e., synchronized
methods imply that object "this" is accessible by no-other-objects
whilst that thread has the lock. Whilst no threads are accessing the
locked portions then readC is concurrent. When they are, readC is
blocked.
For instance, in that previous example, readC is not synchronized
and therefore is not blocked by the synchronized keywords on the
other methods.
No, synchronized methods block the entire instance.
public class Foo {
private int secure;
public Foo() {
secure = 0;
}
// implied lock on "this"
public synchronized int secure() {
return secure;
}
// implicit lock on "this"
public int indenticallySecure() {
// both methods block/queue
// access to instance of Foo!!
synchronized( this ) {
return secure;
}
}
// concurrent only whilst
// no threads have lock on "this"
public int insecure() {
return 1;
}
}
with regards,
--
LD
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden