fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. import java.time.Instant ;
  8. import java.util.List;
  9. import java.util.concurrent.ExecutorService;
  10. import java.util.concurrent.Executors;
  11. import java.util.concurrent.TimeUnit;
  12.  
  13. /* Name of the class has to be "Main" only if the class is public. */
  14. class Ideone
  15. {
  16. public static void main (String[] args) throws java.lang.Exception
  17. {
  18. System.out.println( "Starting. " + Instant.now() );
  19.  
  20. ExecutorService es = Executors.newCachedThreadPool();
  21.  
  22. List < String > messages = List.of( "aaaa" , "bbbb" , "cccc" );
  23. for ( String message : messages )
  24. {
  25. es.submit(
  26. ( ) -> { System.out.println( message ); }
  27. );
  28. }
  29.  
  30. System.out.println( "Tasks submitted to executor service. " + Instant.now() );
  31. try
  32. {
  33. Thread.sleep( TimeUnit.SECONDS.toMillis( 3 ) );
  34. }
  35. {
  36. e.printStackTrace();
  37. }
  38. System.out.println( "Done. " + Instant.now() );
  39.  
  40. }
  41. }
Time limit exceeded #stdin #stdout 5s 38624KB
stdin
Standard input is empty
stdout
Starting. 2020-08-07T18:11:23.658905Z
aaaa
cccc
bbbb
Tasks submitted to executor service. 2020-08-07T18:11:23.722998Z
Done. 2020-08-07T18:11:26.724376Z