class TestSleepMethod1 extends Thread{ public void run(){ for(int i=1;i<5;i++){ try{Thread.sleep(500);}catch(InterruptedException e){System.out.println(e);} System.out.println(i); } } public static void main(String args[])throws Exception{ TestSleepMethod1 t1=new TestSleepMethod1(); TestSleepMethod1 t2=new TestSleepMethod1(); t1.start(); t2.start(); } }
Standard input is empty
1 2 3 4
Exception in thread "main" java.lang.OutOfMemoryError: unable to create new native thread at java.lang.Thread.start0(Native Method) at java.lang.Thread.start(Thread.java:714) at TestSleepMethod1.main(Main.java:13)
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!