Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

java.util.ResourceBundle and thread safety  RSS feed

 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class X
{
private static java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("MyResourceBundle")
private X(){}
public static void m()
{
// is this call thread-safe ?
bundle.getString("message-key");
}
}
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, just realised I should have posted this to the "Threads and Synchronization" forum.
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no problem -- I'll move it to the Threads and Sync forum for you.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Tony Morris:

// is this call thread-safe ?

The creation of the resource bundle is thread-safe as it's done during the static initialization for the class; the variable isn't available to any other thread until it's fully constructed.
After that, except for setParent(), ResourceBundle has no mutator methods; once a ResourceBundle is created, it doesn't change. Therefore, as long as nobody calls setParent(), concurrent calls to getXXX() ought to be fine.
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They were my precisely thoughts as well.
Thanks for the confirmation.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!