Here's some code I saw once. Can you see what's wrong with it?
[updated]
public class ResourceManager1
{
private final String mutex = "";
Object resource = null;
public Object getResource()
{
synchronized (mutex)
{
if (resource == null)
{
resource = new Object();
}
}
return resource;
}
}
public class ResourceManager2
{
private final String mutex = "";
Object resource = null;
public Object getResource()
{
synchronized (mutex)
{
if (resource == null)
{
resource = new Object();
}
}
return resource;
}
}