// 懒汉:
public class Singleton {
private static Singleton obj = null; private Singleton() {
// TODO Auto-generated constructor stub
} public synchronized static Singleton getInstance() {
if (obj == null)
obj = new Singleton();
return obj;
}
}// 饿汉:
public class Singleton {
private static Singleton obj = new Singleton(); /**
 * 
 */
private Singleton() {
// TODO Auto-generated constructor stub
} public static Singleton getInstance() {
  return obj;
}
}