單例模式的同步

//看尚學堂的視頻裏面寫的jvm

public class Jvm {code

private static Jvm jvm;


private Jvm() {

}

public static Jvm getInstance(long time) {

	if (jvm == null) {
	
		synchronized (Jvm.class) {
		
			if (jvm == null) {
			

				try {
				
					Thread.sleep(200);
					
				} catch (InterruptedException e) {
				
					e.printStackTrace();
				}
				
				jvm = new Jvm();
			}
		}
	}
	return jvm;

}

}視頻

相關文章
相關標籤/搜索