1 23 24 package com.rift.coad.lib.thread; 25 26 31 public class ThreadStateMonitor { 32 33 private boolean terminated = false; 35 private long delay = 0; 36 37 40 public ThreadStateMonitor() { 41 } 42 43 44 50 public ThreadStateMonitor(long delay) { 51 this.delay = delay; 52 } 53 54 55 61 public synchronized boolean isTerminated() { 62 return terminated; 63 } 64 65 66 72 public synchronized void terminate(boolean broadCast) { 73 terminated = true; 74 if (broadCast) { 75 notifyAll(); 76 } else { 77 notify(); 78 } 79 } 80 81 82 85 public synchronized void monitor() { 86 try { 87 if (terminated) { 88 return; 89 } 90 if (delay > 0) { 91 wait(delay); 92 } else { 93 wait(); 94 } 95 } catch (Exception ex) { 96 } 98 } 99 } 100 | Popular Tags |