package info.istlab.dp.dp1;
import java.util.Calendar;
import java.util.Date;
class Singleton {
private static Singleton onlyone;
public static Singleton getOnlyOne() {
if (onlyone == null)
onlyone = new Singleton();
return onlyone;
}
Date created;
private Singleton() {
created = Calendar.getInstance().getTime();
}
public String toString() {
return hashCode()+" "+created.toString();
}
}
public class SingletonTest {
public static void main(String[] args) {
// Singleton single = new Singleton();
Singleton single1 = Singleton.getOnlyOne();
System.out.println(single1.toString());
SingletonTest.wait(5);
Singleton single2 = Singleton.getOnlyOne();
System.out.println(single2.toString());
}
public static void wait(int sec) {
try {
Thread.sleep(sec * 1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}