piffy

Executor 1

Jul 17th, 2021
879
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.concurrent.ExecutorService;
  2. import java.util.concurrent.Executors;
  3. import java.util.concurrent.TimeUnit;
  4.  
  5. public class Esempio1 {
  6.  
  7.     public static void main(String[] args) {
  8.         Runnable r = () -> System.out.println("Thread 1");
  9.  
  10.         ExecutorService executorService = Executors.newSingleThreadExecutor();
  11.         executorService.execute(r);
  12.         System.out.println("Main");
  13.         executorService.shutdown();
  14.         try {
  15.             executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
  16.         } catch (InterruptedException e) { }
  17.        
  18.     }
  19. }
  20.  
RAW Paste Data