Advertisement
Guest User

Untitled

a guest
Feb 9th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. private void cronJob(long interval) {
  2. ExecutorService executor = Executors.newFixedThreadPool(50);
  3. CompletionService<ArrayList<Element>> compService = new ExecutorCompletionService<>(executor);
  4.  
  5. for (Task task : tasks) {
  6. compService.submit((Callable<ArrayList<Element>>) task);
  7. }
  8. for (Task task : tasks) {
  9. Future<ArrayList<Element>> future = compService.take();
  10. ArrayList<Element> list = future.get();
  11. for (Element e : list) {
  12. e.update();
  13. }
  14. }
  15.  
  16. executor.shutdown();
  17. executor.awaitTermination(Long.MAX_VALUE , TimeUnit.NANOSECONDS);
  18. //Wait for interval period and repeat
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement