1 22 23 24 package com.mchange.v1.lang; 25 26 32 public abstract class GentleThread extends Thread 33 { 34 boolean should_stop = false; 35 boolean should_suspend = false; 36 37 public GentleThread() 38 { super(); } 39 40 public GentleThread(String name) 41 { super( name ); } 42 43 public abstract void run(); 44 45 48 public synchronized void gentleStop() 49 {should_stop = true;} 50 51 54 public synchronized void gentleSuspend() 55 {should_suspend = true;} 56 57 60 public synchronized void gentleResume() 61 { 62 should_suspend = false; 63 this.notifyAll(); 64 } 65 66 72 protected synchronized boolean shouldStop() 73 {return should_stop;} 74 75 83 protected synchronized boolean shouldSuspend() 84 {return should_suspend;} 85 86 96 protected synchronized void allowSuspend() throws InterruptedException 97 {while (should_suspend) this.wait();} 98 } 99 | Popular Tags |