Guest User

Untitled

a guest
Mar 7th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. import java.util.LinkedList;
  2. import java.util.Queue;
  3. import java.util.concurrent.ExecutorService;
  4. import java.util.concurrent.Executors;
  5. import java.util.concurrent.TimeUnit;
  6. import java.util.Random;
  7. public class Console {
  8.  
  9. public static void main(String[] args) throws InterruptedException {
  10. System.out.println("asd");
  11. final Queue<DemoThread> queue = new LinkedList<>();
  12.  
  13. ExecutorService user = Executors.newCachedThreadPool();
  14. ExecutorService processor = Executors.newSingleThreadExecutor();
  15. user.submit(new Runnable(){
  16. public void run(){
  17. while (!Thread.currentThread().isInterrupted()) {
  18. if(!queue.isEmpty()){
  19. DemoThread temp = queue.poll();
  20. System.out.println(temp);
  21. processor.submit(temp);
  22. }
  23. }
  24. }
  25. });
  26.  
  27. user.submit(new Runnable() {
  28. @Override
  29. public void run() {
  30. System.out.println("asdasdasdasdasdasdasd");
  31. queue.add(new DemoThread(2000));
  32. queue.add(new DemoThread(500));
  33. queue.add(new DemoThread(3000));
  34. queue.add(new DemoThread(100));
  35. System.out.println(queue);
  36. try {
  37. Thread.sleep(1000);
  38. } catch (InterruptedException e) {
  39. e.printStackTrace();
  40. }
  41. queue.add(new DemoThread(1666));
  42. System.out.println(queue);
  43. }
  44. });
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment