You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

16 lines
331 B

package singleton;
/*
* 枚举方式, 不仅解决了线程同步,也防止了反序列化
* */
public enum Singleton8 {
INSTANCE;
public static void main(String[] args) {
for (int i=0; i< 100; i++){
new Thread(() -> System.out.println(Singleton8.INSTANCE.hashCode())).start();
}
}
}