• Post Reply Bookmark Topic Watch Topic
  • New Topic

ResourceBundle.getBundle() deadlock when called inside a synchronized thread  RSS feed

 
Ricardo Soza
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm getting a dead lock on ResourceBundle.getBundle() when run below. Dead lock only happens in Java 1.6, but works fine in Java 1.4 and 1.5.

Attached below is a way to reproduce the deadlock... This sample code is an over simplification of the actual usage, but ResourceBundle.getBundle does need to get called from the thread that gets launched from an object that is synchronized.


 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch, Ricardo.

Could you please Use Code Tags though? You can edit your post to add them.
 
Ireneusz Kordal
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Start program,run JConsole, connect to the process,
click on the "Threads" tab in the JConsole main window, then find your blocked thread and display it's stack trace.
You'll see that the thread is blocked on java.util.ResourceBundle.endLoading(ResourceBundle.java) method.

So, lest's look at source code of this method:
http://www.docjar.com/html/api/java/util/ResourceBundle.java.html


hmmm, it looks that this method retrieves the current thread to 'me',
tries to synchronize on it and call to notifyAll on it.

But what is it in 'me' ? This is a reference to the current thread,
that is instance of TestDevice.
But wait a moment ... in the main thread there is a synchronized block
that is synchronized on .... the same TestDevice object !

Lets try to release monitor on 'device' inside the main thread:


Compile, run and ....
run:
Entering run...
setting running=false
closing....

Exception in thread "Thread-0" java.util.MissingResourceException: Can't find bundle for base name sun.text.resources.DateFormatZoneData, locale en_US
at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1521)
at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1260)
at java.util.ResourceBundle.getBundle(ResourceBundle.java:787)
at test.TestDevice.run(TestDevice.java:24)
BUILD SUCCESSFUL (total time: 0 seconds)


yippee - deadlock unblocked

 
Colin Bester
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My question is why the difference between Java versions (they don't call endpoint as in 6.0). Seems to be a pretty severe, java imposed, limitation.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
During a major version update (and even between minor version updates) the source code of the classes in the core API may be partially, or even completely, rewritten to gain performance or fix bugs. Apparently Sun found it necessary to change ResourceBundle.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!