Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.concurrent.*;
- class CheckResults {
- private static int counter = 0;
- public static void main(String[] args) throws InterruptedException, ExecutionException {
- ExecutorService service = null;
- try {
- service = Executors.newSingleThreadExecutor();
- Future<?> result = service.submit(() -> {
- for (int i = 0; i < 500000; i++) CheckResults.counter++;
- });
- result.get(1, TimeUnit.NANOSECONDS);
- System.out.println("Reached!");
- } catch (TimeoutException e) {
- e.printStackTrace();
- System.out.println("Not reached in time!");
- } finally {
- if (service != null) service.shutdown();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement