1 4 package com.tc.util.concurrent; 5 6 15 public class StoppableThread extends Thread implements LifeCycleState { 16 17 private volatile boolean stopRequested = false; 18 19 public StoppableThread() { 20 super(); 21 } 22 23 public StoppableThread(Runnable target) { 24 super(target); 25 } 26 27 public StoppableThread(String name) { 28 super(name); 29 } 30 31 public StoppableThread(ThreadGroup group, Runnable target) { 32 super(group, target); 33 } 34 35 public StoppableThread(Runnable target, String name) { 36 super(target, name); 37 } 38 39 public StoppableThread(ThreadGroup group, String name) { 40 super(group, name); 41 } 42 43 public StoppableThread(ThreadGroup group, Runnable target, String name) { 44 super(group, target, name); 45 } 46 47 public StoppableThread(ThreadGroup group, Runnable target, String name, long stackSize) { 48 super(group, target, name, stackSize); 49 } 50 51 public boolean isStopRequested() { 52 return stopRequested; 53 } 54 55 public void requestStop() { 56 this.stopRequested = true; 57 } 58 59 public boolean stopAndWait(long timeout) { 60 requestStop(); 61 try { 62 join(timeout); 63 } catch (InterruptedException e) { 64 } 66 return !isAlive(); 67 } 68 69 } 70 | Popular Tags |