Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class RunShitThread extends Thread
- {
- private volatile boolean running = true;
- private volatile boolean hasNewRunnable = false;
- private volatile Runnable runnable;
- public void run()
- {
- while (running)
- {
- try
- {
- waitForNotify();
- }
- catch (InterruptedException ignored)
- {
- continue;
- }
- if (runnable != null)
- {
- runnable.run();
- }
- runnable = null;
- }
- }
- public synchronized void waitForNotify() throws InterruptedException
- {
- while (!hasNewRunnable)
- {
- wait();
- }
- }
- public synchronized void setRunnable(Runnable r)
- {
- runnable = r;
- hasNewRunnable = true;
- }
- public synchronized void fuckOffDumbThread()
- {
- running = false;
- }
- }
Add Comment
Please, Sign In to add comment