Advertisement
piffy

Executor 1

Jul 17th, 2021
3,096
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.60 KB | None | 0 0
  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.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement