Advertisement
Guest User

Untitled

a guest
Jan 25th, 2020
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.44 KB | None | 0 0
  1. class Huilo extends Thread {
  2.  
  3.     private final Queue<Runnable> queue = Queues.newArrayDeque();
  4.  
  5.     @Override
  6.     public void run() {
  7.         synchronized(queue) {
  8.             while(queue.isEmpty()) {
  9.                 queue.poll().run();
  10.             }  
  11.         }
  12.     }
  13.  
  14.     // И в таске может быть овер сложная задача, которая займет дохуя мс
  15.     public void runTask(Runnable task) {
  16.         synchronized(queue) {
  17.             queue.add(task);   
  18.         }
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement