jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes Doubt in Threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Doubt in Threads" Watch "Doubt in Threads" New topic

Doubt in Threads

Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
Hi all,
When a thread enters a synchronized method, whether that particular thread acquires the lock only for that method or the whole object in which the method is contained.

Example :

So when a thread accesses the synchronized method setValue() can any other thread access the other synchronized method getValue() ..
[ April 06, 2005: Message edited by: Srinivasa Raghavan ]

Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
Thanks this example helped me.
Hentay Duke
Ranch Hand

Joined: Oct 27, 2004
Posts: 198
Aaaaa... you're welcome?
marc weber

Joined: Aug 31, 2004
Posts: 11343

As (I hope) you've discovered, the synchronized keyword invokes the object lock, or -- in the case of static code -- the class lock.

As of 1.5, you can use a ReentrantLock to lock specific blocks of code.

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
I agree. Here's the link: http://aspose.com/file-tools
subject: Doubt in Threads
It's not a secret anymore!