Guest User

Untitled

a guest
Jan 23rd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. private void produceConsume() {
  2. try {
  3. Thread producer = new Thread(new Runnable() {
  4. //actual implementation omitted
  5. });
  6. producer.start();
  7.  
  8. List<Thread> consumers = new ArrayList<>();
  9.  
  10. for (int i = 0; i < noOfThreads; i++) {
  11.  
  12. Thread consumer = new Thread(new Runnable() {
  13. //actual implementation omitted
  14. });
  15. consumer.start();
  16. consumers.add(consumer);
  17. }
  18.  
  19. for (Thread t : consumers) {
  20. t.join();
  21. }
  22. producer.join();
  23.  
  24. } catch (Exception e) {
  25. LOG.error("InterruptedException e: " + e.getMessage(), e);
  26. } finally {
  27. LOG.info("We are done with this file!");
  28. }
  29. }
Add Comment
Please, Sign In to add comment