fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10.  
  11. static class Foo implements Runnable
  12. {
  13. int n;
  14. Foo(int n) { this.n = n; }
  15. public void run() {
  16. try {
  17. Thread.sleep(20);
  18. System.out.println(n);
  19. } catch (Exception e) {
  20. e.printStackTrace();
  21. }
  22. }
  23. }
  24.  
  25. public static void main (String[] args) throws java.lang.Exception
  26. {
  27. // your code goes here
  28. for (int i = 0; i < 100; i++) {
  29. Thread t = new Thread(new Foo(i));
  30. t.start();
  31. }
  32. }
  33. }
Runtime error #stdin #stdout #stderr 0.08s 382848KB
stdin
Standard input is empty
stdout
0
6
5
4
3
2
1
stderr
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:693)
	at Ideone.main(Main.java:30)