• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread synchronisation - Using a string literal for locking

 
O. Ziggy
Ranch Hand
Posts: 430
Android Debian VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 430
Android Debian VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ill answer my own question:
The code is not actually synchronising on the str object..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic