Adobe Interview Question
Computer ScientistsTeam: PSE
Country: India
Interview Type: In-Person
Java Perspective: Number of ways:
you can use synchronization - actually that is the first thing that should come to mind whenever encountering questions involving multithreaded environment plus single access.
The thing is, synchronization is needed only once since it is expensive in its nature.
See this example:
public class Singleton
{
private Singleton instance;
private Singleton(){}
public Singleton getInstance()
{
if(instance==null)
{
synchronized(Singleton.this)
{
instance = new Singleton();
}
}
return instance;
}
}
use enum...
- sujita July 16, 2012