Let say I have the following method, is the method thread safe?
public static void forwardProcessingPerStudy(String str)
{
someNonStaticMethodProcessingOnObj(str);
}
I.e: Could two separate threads run the above method at the same time passing different instance of str ( say two completely different string objects ) and conflict with each other?
For the method to be safe for thread use do I have to make it a synchronized method?
Yes, two different threads could both run that method at the same time, with either the same string reference or a different one.
As to whether you need to synchronize, that entirely depends on what
someNonStaticMethodProcessingOnObjdoes. The name implies it’s calling a non-static method, but given that you don’t specify an instance on which to call it, that seems unlikely.If the body of the method (and any methods that are called) doesn’t do anything with any shared state, you don’t need to worry. If it does, you need to think more carefully.