SHARE
TWEET

Untitled

a guest Apr 18th, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.concurrent.*;
  2.  
  3. class CheckResults {
  4.     private static int counter = 0;
  5.  
  6.     public static void main(String[] args) throws InterruptedException, ExecutionException {
  7.         ExecutorService service = null;
  8.         try {
  9.             service = Executors.newSingleThreadExecutor();
  10.             Future<?> result = service.submit(() -> {
  11.                 for (int i = 0; i < 500000; i++) CheckResults.counter++;
  12.             });
  13.             result.get(1, TimeUnit.NANOSECONDS);
  14.             System.out.println("Reached!");
  15.         } catch (TimeoutException e) {
  16.             e.printStackTrace();
  17.             System.out.println("Not reached in time!");
  18.         } finally {
  19.             if (service != null) service.shutdown();
  20.         }
  21.     }
  22. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top