The Artima Developer Community
Sponsored Link

Yes, only one thread at a time

Advertisement

Advertisement

This page contains an archived post to the Design Forum (formerly called the Flexible Java Forum) made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Yes, only one thread at a time

Posted by Bill Venners on 12 Aug 1998, 2:43 PM

>
> I am not sure, but I am guessing that the following example will only allow one thread in ONE OF THE SECTIONS at one given time. Since the example uses the same lock object to all the sections. Do I understand currectly?

>


> void someUnsynchMethod() {

> synchronized(this) {
> do some critical section stuff;
> }

> do something piddly that isn't a critical section;

> synchronized(this) {
> do some more critical section stuff;
> }

> do something else piddly that isn't a critical section;

> synchronized(this) {
> do some more critical section stuff;
> }

> do something else piddly that isn't a critical section;

> synchronized(this) {
> do some more critical section stuff;
> }
> }
>

Yes, only one thread at a time will be allowed in any one
of these critical sections, because they all lock the same
object.

bv



Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us