Monday, 26 August 2013

Is this utility class with 2 static methods threadsafe?

Is this utility class with 2 static methods threadsafe?

The following Utility class calls within itself the same static methods,
but has no shared global variables. But it looks like the method nameTo()
is "shared" and an issue. Am I right with it, and that it's unsafe?
public class Utility
{
public static MyObject create_1(boolean b)
{
MyObject o = new MyObject();
o.setName(nameTo(b));
return o;
}
public static MyObject create_2(boolean b)
{
MyObject o = new MyObject();
o.setName(nameTo(b));
return o;
}
public static String nameTo(boolean b)
{
if(b)
return "NameA";
else
return "NameB";
}
}

No comments:

Post a Comment