• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Running concurrent Mulithreaded Application
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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
  • Follow-Ups:
    • Re: Running concurrent Mulithreaded Application
      • From: Mike Schrag <email@hidden>
References: 
 >Running concurrent Mulithreaded Application (From: Tanmoy Roy <email@hidden>)
 >Re: Running concurrent Mulithreaded Application (From: Praveen Boppana <email@hidden>)
 >Re: Running concurrent Mulithreaded Application (From: David Koski <email@hidden>)
 >Re: Running concurrent Mulithreaded Application (From: Tanmoy Roy <email@hidden>)
 >Re: Running concurrent Mulithreaded Application (From: Praveen Boppana <email@hidden>)
 >Re: Running concurrent Mulithreaded Application (From: David LeBer <email@hidden>)
 >Re: Running concurrent Mulithreaded Application (From: LD <email@hidden>)
 >Re: Running concurrent Mulithreaded Application (From: Mike Schrag <email@hidden>)

  • Prev by Date: Re: Changing value of a WOConditional binding inside WORepetition
  • Next by Date: Re: Running concurrent Mulithreaded Application
  • Previous by thread: Re: Running concurrent Mulithreaded Application
  • Next by thread: Re: Running concurrent Mulithreaded Application
  • Index(es):
    • Date
    • Thread