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

static synchronized  RSS feed

 
Sureshkumar Chinnappan
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,
I am working to improve my application performance. While looking the code I have seen the following implementation.
---------------------
Class TestClass{

Obejct param=null;

private TestClass(Object param){
this.param = param;
}

public static synchronized TestClass getInstance (Object param)
{
return new TestClass (param);
}

}
--------------------
The applicaiton is running on multiple threads. Should the above getInstance method require synchronization? I am thinking its not required hence we are creating a new object here. Please advice me.
thanks in advance.
[ February 14, 2008: Message edited by: Sureshkumar Chinnappan ]
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Correct - there's no need for synchronization here. You aren't accessing any mutable data.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!