import java.io.File; import java.io.FileOutputStream; import java.io.ObjectOutputStream; import java.io.Serializable; public class BigSingleton implements Serializable { private static BigSingleton self; private byte[] array; private BigSingleton(int size) { array = new byte[size * 1024 * 1024]; System.out.println(array.length); } private BigSingleton() { throw new IllegalStateException(); } public static BigSingleton getInstance() { if (self == null) { File file = new File("BigSingleton.ser"); try { self = new BigSingleton(100); } catch (Exception e) { e.printStackTrace(); } try { file.createNewFile(); FileOutputStream fis = new FileOutputStream(file); ObjectOutputStream oos = new ObjectOutputStream(fis); oos.writeObject(self); oos.flush(); oos.reset(); System.out.println("BigSingleton written to file"); } catch (Exception e) { e.printStackTrace(); } } return self; } public static void main(String[] args) { } }