File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Thread synchronisation - Using a string literal for locking Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Thread synchronisation - Using a string literal for locking" Watch "Thread synchronisation - Using a string literal for locking" New topic
Author

Thread synchronisation - Using a string literal for locking

O. Ziggy
Ranch Hand

Joined: Oct 02, 2005
Posts: 430



The above test produces the following output



I don't understand why the last three thread are not using the String object as a shared lock like the first three threads. Even though they last three threads are using a different instance of 'RunnableThread', shouldnt they be synchronised because there is only once copy for 'str' in the string constant pool?

Thanks
O. Ziggy
Ranch Hand

Joined: Oct 02, 2005
Posts: 430

Ill answer my own question:
The code is not actually synchronising on the str object..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Thread synchronisation - Using a string literal for locking
 
Similar Threads
Thread
Lease pattern
Synchronozation How it Works
Locking & Synchronization on Bodgitt & Scarper
Please explain this code