fork(3) 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 Main {
  9. public static void main (String[] args) throws java.lang.Exception {
  10. List<String> l = new ArrayList<String>();
  11. l.add("first");
  12. l.add("second");
  13.  
  14. List<Thread> threads = new ArrayList<Thread>();
  15. for (String s : l) {
  16. final String innerS = s;
  17. Thread thread = new Thread() {
  18. public void run() {
  19. System.out.println(innerS);
  20. }
  21. };
  22. threads.add(thread);
  23. thread.start();
  24. }
  25.  
  26. for (Thread t : threads)
  27. t.join();
  28. }
  29. }
Success #stdin #stdout 0.07s 381888KB
stdin
Standard input is empty
stdout
first
second