ThatGamerBlue2

Untitled

Mar 14th, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.72 KB | None | 0 0
  1. public class RunShitThread extends Thread
  2. {
  3.     private volatile boolean running = true;
  4.     private volatile boolean hasNewRunnable = false;
  5.     private volatile Runnable runnable;
  6.  
  7.     public void run()
  8.     {
  9.         while (running)
  10.         {
  11.             try
  12.             {
  13.                 waitForNotify();
  14.             }
  15.             catch (InterruptedException ignored)
  16.             {
  17.                 continue;
  18.             }
  19.             if (runnable != null)
  20.             {
  21.                 runnable.run();
  22.             }
  23.             runnable = null;
  24.         }
  25.     }
  26.  
  27.     public synchronized void waitForNotify() throws InterruptedException
  28.     {
  29.         while (!hasNewRunnable)
  30.         {
  31.             wait();
  32.         }
  33.     }
  34.  
  35.     public synchronized void setRunnable(Runnable r)
  36.     {
  37.         runnable = r;
  38.         hasNewRunnable = true;
  39.     }
  40.  
  41.     public synchronized void fuckOffDumbThread()
  42.     {
  43.         running = false;
  44.     }
  45. }
Add Comment
Please, Sign In to add comment