Is getString() method in ResourceBundle thread safe?

Is getString() method in ResourceBundle thread safe?

i was just thinking about the following scenario.
Lets assume that there are 2 threads accessing the same ResourceBundle object.
and are calling getString(key) method. In this case if thread1 passes key1 and thread2 passes key2, there might be a chance that both the threads get the same value as the counter is shared across these threads. I believe if ResourceBundle uses some synchronized objects like HashTable, then we are sure that it is thread safe.
Let me know your comments on this pls.

Similar Messages

  • Are static methods in Java thread safe?

    Are static methods in Java thread safe?
    thanks,
    suresh

    if static method use the instance variable
    You mean member variable, where member variables are either class variables (static) or instance variables (non-static).
    then you have to make it thread safe using
    synchronization Not necessarily. Depends on requirements and usage context.
    else in case of local var. it
    is thread safe. Not necessarily. That local variable could refer to an object that's visible to multiple threads.
    Statements like "Local variables are threadsafe but member variables aren't" are an oversimplification.
    Something is threadsafe if it cannot be made to behave incorrectly simply by running it in a multithreaded context. Determining that can be very difficult.

  • Native library NOT thread safe - how to use it via JNI?

    Hello,
    has anybody ever tried to use a native library from JNI, when the library is not thread safe?
    The library (Windows DLL) was up to now used in an MFC App and thus was only used by one user - that meant one thread - at a time.
    Now we would like to use the library like a "server": many Java clients connect the same time to the library via JNI. That would mean each client makes its calls to the library in its own thread. Because the library is not thread safe, this would cause problems.
    Now we discussed to load the library several times - separately for each client (for each thread).
    Is this possible at all? How can we do that?
    And do you think we can solve the problem in this way?
    Are there other ways to use the library, though it is not thread safe?
    Any ideas welcome.
    Thanks for any contributions to the discussion, Ina

    (1)
    has anybody ever tried to use a native library from
    JNI, when the library (Windows DLL) is not thread safe?
    Now we want many Java clients.
    That would mean each client makes its calls
    to the library in its own thread. Because the library
    is not thread safe, this would cause problems.Right. And therefore you have to encapsulate the DLL behind a properly synchronized interface class.
    Now the details of how you have to do that depends: (a) does the DLL contain state information other than TLS? (b) do you know which methods are not thread-safe?
    Depending on (a), (b) two extremes are both possible:
    One extreme would be to get an instance of the interface to the DLL from a factory method you'll have to write, where the factory method will block until it can give you "the DLL". Every client thread would obtain "the DLL", then use it, then release it. That would make the whole thing a "client-driven" "dedicated" server. If a client forgets to release the DLL, everybody else is going to be locked out. :-(
    The other extreme would be just to mirror the DLL methods, and mark the relevant ones as synchronized. That should be doable if (a) is false, and (b) is true.
    (2)
    Now we discussed to load the library several times -
    separately for each client (for each thread).
    Is this possible at all? How can we do that?
    And do you think we can solve the problem in this
    way?The DLL is going to be mapped into the process address space on first usage. More Java threads just means adding more references to the same DLL instance.
    That would not result in thread-safe behavior.

  • Thread safe servlets

    I have a question regarding the semantice of servlets. Consider you are calling a method
    public StringmodifyAddress(){......}in the service method of the servlet. Now considering that a servlet could be sericing multiple requests would this method be technically thread safe? If not what could we do to make it safe.
    cheers

    Ok let me rephrase and provide a little more details. Sorry I messed up the question the first time
    private String email;
    public void doPost(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException
       User user = new User;
       String address =  user.modifyAddress(email);
    }Now in the class User
    public String modifyAddress(String email)
      //writes the email address to a database
    }Now I feel since user is a variable local to the service method it is thread safe, but a coworker feels that since email is a member variable it would not be thread safe. Please advise it seems that he might be correct.

  • Is KeyStore thread safe?

    Hi all,
    My class has KeyStore instance as static field.
    When KeyStore#getKey(String alias, char[] password) mthod is called with right alias and password on multi-thread environment, normaly I can get Key object successfully.
    But rarely following UnrecoverableKeyException is thrown from that method.
    Caused by: java.security.UnrecoverableKeyException: Given final block not properly padded
         at com.sun.crypto.provider.SunJCE_z.a(DashoA13*..)
         at com.sun.crypto.provider.JceKeyStore.engineGetKey(DashoA13*..)
         at java.security.KeyStore.getKey(KeyStore.java:763)Is KeyStore (specifically JceKeyStore) thread safe?
    Thanks in advance.

    In general a Java API class or method isn't thread safe unless it is specifically so documented.
    You could always synchronize it and see if it helps ...

  • Is TelemetryClient thread-safe?

    The only tutorial for client events I found is down at the moment (404):
    http://azure.microsoft.com/en-us/documentation/articles/app-insights-web-track-usage-custom-events-metrics
    However looking at the cached version, it doesn't mention threading concerns.
    The docs say its methods are not thread safe but I'm wondering if that's just the boilerplate template. If it really isn't thread safe, what
    is the recommended practice in a multi-threaded environment? lock around each call? instantiate a new client for each call? synchronize calls in a queue?
    Thanks,
    Ohad

    Hi Oleg, thanks for clarifying that.
    Perhaps you could modify the docs to point that out.
    I'm confused though, why pay the overhead of thread-safety if you recommend creating a new instance every time?
    BTW I don't know if it was your doing, but the
    article is back online :)

  • Is Clone thread safe?

    I am examining property change class and notice that it does an unsynchronized clone of vector. This makes me wonder if clone is thread safe? it must be or this clone could experience the same problems of copying the vector while its being modified.
    Anybody know if clone is indeed thread safe?

    Of course your clone() method can be thread safe if
    you want it to be; simply make your overriding clone() method
    synchronized ...I still don't think this will be thread-safe, unless all methods that
    change data in the object are also synchronized. Even then you can't
    be sure unless you declare your class final, because otherwise
    someone else could add non-threadsafe methods later.Sure, that's why I emphasised '*your* clone() method'. What others
    do to it is up to them ;-)
    kind regards,
    Jos

  • Is this statement thread safe?

    Please tell whether the following statement is thread safe.
    counter++;
    (whether it is necessary to place it inside synchronized??)
    thanks,
    hawkins

    I believe the operation you describe is atomic so is "synchronized" if you prefer.
    That doesn't mean that your method will be thread-safe, though. An individual operation does no damage on its own - it's only when something else happens that thread-safety becomes an issue.
    If your question is "will my counter increase by 2 if two threads call counter++ at the same time?" then the answer is "yes".
    Thread-safety concerns the order in which operations happen across multiple threads, not whether they happen.
    If you're still not sure then please post up some context about what you're trying to do and perhaps some code to indicate where you think there may be a risk with concurrent access.

  • Are WLE libraries thread safe?

    Hi,
    Can we implement multiple threads in c CORBA Servers. Are C libraries thread safe? Can i use pthread to create threads in WLE CORBA C servers
    regards,
    Manoj PG

    JSPs/Servlets are not threadsafe in that one instance of the class is created to handle all requests.
    But only your class attributes are not thread-safe. Local variables are stored for each invocation of the service method, and are thread safe.
    Basically you have to declare all your variables inside a method, and if you call any java methods, pass parameters.
    <%!
      int myNumber;   // class attribute - shared among all calls to this servlet
    %>
    <%
      int myLocalNumber; // local variable to method.  will be threadsafe
    %>In short, yes this code is threadsafe. The key will be the same when you get back from doing your "stuff".
    The only problem would be if two people hit it fast enough to get the same time, and thus the same key.
    Cheers,
    evnafets

  • How to know whether a method is thread-safe through the java-doc?

    In some book, it says that SAXParserFactory.newSAXParser() is thread-safe,but in the java-doc,it doesn't say that.
    newSAXParser
    public abstract SAXParser newSAXParser()
    throws ParserConfigurationException,
    SAXExceptionCreates a new instance of a SAXParser using the currently configured factory parameters.
    Returns:
    A new instance of a SAXParser.
    Throws:
    ParserConfigurationException - if a parser cannot be created which satisfies the requested configuration.
    SAXException - for SAX errors.
    I want to know, how to know whether a method is thread-safe?

    System.out is a PrintStream object. None of the methods there use the synchronized modifier, but if you look in the source code, you will find out it is thread-safe, because it will use synchronized blocks whenever it writes some text.
    The source code is in the src.jar file which you can extract.
    I didn't find any comments about that PrintStream is thread-safe in the API.

  • How can I get to know if a method is threads-safe?

    Hi, there.
    How can I get to know if a method is threads-safe?
    For example, in two different threads, is System.out.print() method safe or not?And where can I find the information with regard to this?
    thanks very much.

    System.out is a PrintStream object. None of the methods there use the synchronized modifier, but if you look in the source code, you will find out it is thread-safe, because it will use synchronized blocks whenever it writes some text.
    The source code is in the src.jar file which you can extract.
    I didn't find any comments about that PrintStream is thread-safe in the API.

  • Are methods in the Graphics class Thread Safe

    Can methods from the Graphics class (.e.g. drawImage(), drawString(), ect..) be called from any thread? In other words, can two threads that refer to the same Graphics object step on each other methods calls?
    TIA,
    DB
    Edited by: Darth_Bane on Apr 27, 2009 1:44 PM

    No,
    They are GUI activities so you should call them from the Swing Thread ( Event Disptach Thread)
    Now for the JComponent the following are thread safe:
    repaint(), revalidate, invalidate which can be called from any thread.
    Also the listener list can be modified from any thread addListenerXX or removeListenerXX where XX is ListenerType
    Regards,
    Alan Mehio
    London, UK

  • Are Static methods Thread safe?

    Hello All
    I have a static method that takes a integer and returns a mathematically processed result.
    Since this method is frequently required, I have placed it in a common class and declared it as static.
    I want to know whether this method is thread safe?

    There's nothing special about static methods, with regard to thread safety. If they access shared objects, then such access will usually need to be controlled by synchronisation; this might be on the object being accessed, some higher-level object or a special object allocated purely as a lock. The only way that you might think of them as special is that there's no instance of the Class on which you can synchronise.
    You can declare a static method as synchronised. If you do, it will be synchronised on the single Class object of the class in which it is declared. This means that only one thread can be executing any part of the method at any one time. However, I understand that the Java Runtime itself sometimes synchronises on this Class object for its own reasons, therefore you might sometimes find a synchronised static method blocks when no other thread is executing it. Usually better, therefore, to explicitly synchronise on some object or other, than to use synchronised static methods.

  • Is this method thread safe?

    Hi Guys
    I have the following code:
    public class MyClass extends HttpServlet {
         HttpSession session;
         public doGet(HttpServletRequest request, HttpServletResponse response)
                                      throws IOException, ServletException                              
              session = request.getSession(false);
              List<AClass> htransactions = (List<AClass>)session.getAttribute("AClass");
                   //do stuff here
    }What I want to know is that if the HttpSession session is declared as a instance variable, does this make it non thread safe? Or is using such a way of for a session fine?
    .

    Steve declared a thumb-rule.
    Bear Bibeault
    sheriff & author
    Member # 24697
    posted Yesterday 9:17 PM
    Yes, variables created inside methods are safe because each thread will get their own copies. Instance variables are unsafe because they are shared across all threads.
    Keep this in memory, hope this was a perfect clarification...you can declare now on the answer.

  • Are the service(), doPost() and doGet() methods THREAD-SAFE?

    Please Let Me know If service(), doPost() and doGet() are Thread-safe. If they are not thread safe, How to make them thread-safe?

    Please Let Me know If service(), doPost() and doGet() are Thread-safe. They are not.
    If they are not thread safe, How to make them thread-safe?The best way is to avoid writing code that depends on a servlet's thread safety; i.e., no servlet instance variables - keep everything local to the method. Else, you'll want to learn about synchronization.
    [JavaWorld article - Write thread-safe servlets|http://www.javaworld.com/javaworld/jw-07-2004/jw-0712-threadsafe.html].
    ~

Maybe you are looking for

  • I am having issues installing my router!

    i have recently purchased a wireless-G broadband router it's model is WRT54G. i plugged in my modem to the router and them my comp i made sure that the router and every thing was plugged in and all the lights that are suppose 2 be on are on. but once

  • SHARE TIME CAPSULE AS THROUGH INTERNET WITH WINDOWS 7 SMB

    SHARE TIME CAPSULE AS THROUGH INTERNET WITH WINDOWS 7 SMB

  • Camera Raw 7.3 prblem

    Since I have updated to Camera Raw 7.3, I can only process 1-3 files before it stops working. (Vista SP2, 4 gig mem). I never had a problem with 7.2 and would like to revert to that update. Can it be done, if so, how?

  • External Def activation error

    Hi Experts I am trying to activate an xsd that has been generated under the external definitions, but it is giving the following error, Can anyone let me know how to avoid this error and activate the xsd. DB2 SQL Error: SQLCODE=-913, SQLSTATE=57033,

  • Why not found "ligp.dll" in Tuxedo /WS 8.0 ?

    Environment: Before 1.Power Builder 5 2.Tuxedo Client 6.4 3.Tuxedo Server 6.4 Afeter 1.Power Builder 8 2.Tuxedo Client 8.0 3.Tuxedo Server 8.0 Before to upgrade software, I use power builder to call function "tuxputenv" from "libgp.dll" in path c:\tu