package design.singleton.demo;
public class SingletonHungryEntity {
private static SingletonHungryEntity s = new SingletonHungryEntity();
public static SingletonHungryEntity getSingletonEntity() {
return s;
}
private SingletonHungryEntity() {
}
}
package design.singleton.demo;
public class Main {
public static void main(String[] args) {
Thread t1 = new Thread() {
@Override
public void run() {
SingletonHungryEntity s = SingletonHungryEntity.getSingletonEntity();
System.out.println("t1线程获取对象的hashcode: " + s.hashCode());
}
};
Thread t2 = new Thread() {
@Override
public void run() {
SingletonHungryEntity s = SingletonHungryEntity.getSingletonEntity();
System.out.println("t2线程获取对象的hashcode: " + s.hashCode());
}
};
Thread t3 = new Thread() {
@Override
public void run() {
SingletonHungryEntity s = SingletonHungryEntity.getSingletonEntity();
System.out.println("t3线程获取对象的hashcode: " + s.hashCode());
}
};
t1.start();
t2.start();
t3.start();
}
}