Created
January 12, 2018 19:49
-
-
Save sheva29/f29dbe17340d342c729c2d3bb93cd912 to your computer and use it in GitHub Desktop.
Parelelizing Void Method in Java using google Thread Factory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ThreadFactory factory = com.google.appengine.api.ThreadManager.currentRequestThreadFactory(); | |
ExecutorService service = new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors(), 16, 60, TimeUnit.SECONDS, new SynchronousQueue<>(), factory); | |
List<Future<Void>> futures = new ArrayList<>(); | |
for (String tempStopAccountId : aristoDto.getTempStopHdAccountIds()) { | |
if (aristoDto.getProductFileDtoMap().get(tempStopAccountId) != null) { | |
aristoDto.getProductFileDtoMap().get(tempStopAccountId).setTempAccount(true); | |
} | |
Callable<Void> callable = () -> { | |
futures.add(processCancellation(tempStopAccountId)); | |
return null; | |
}; | |
futures.add(service.submit(callable)); | |
} | |
service.shutdown(); | |
log.info("Waiting for temp calls to come back"); | |
for (Future<Void> future : futures){ | |
try { | |
future.get(); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} catch (ExecutionException e) { | |
e.printStackTrace(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment