Should calls to new() be protected by synchronized block?
Posted on 2006-06-12
As we know, each thread is awarded a Java stack, which contains data no other thread can access, including the local variables, parameters, and return values of each method the thread has invoked. What about the object references?
Consider the following method:
Myclass1 func(Myclass2 obj2)
Myclass1 obj1 = new Myclass1(obj2);
Assume that this method is being called by many threads simultaneously, each passing its own value for obj2, should I protect th execution of line Myclass1 obj1 = new Myclass1(obj2) through a synchronized block?