1 21 22 package com.rift.coad.daemon.messageservice; 23 24 import org.apache.log4j.Logger; 26 27 28 33 public class ProcessMonitor { 34 35 private static ProcessMonitor singleton = null; 37 38 protected Logger log = 40 Logger.getLogger(ProcessMonitor.class.getName()); 41 42 private boolean terminated = false; 44 45 48 private ProcessMonitor() { 49 } 50 51 52 57 public static synchronized ProcessMonitor getInstance() { 58 if (singleton == null) { 59 singleton = new ProcessMonitor(); 60 } 61 return singleton; 62 } 63 64 65 70 public synchronized void monitor(long delay) { 71 try { 72 if (terminated) { 73 return; 74 } 75 76 if (delay < 0) { 77 log.warn("Negative value of [" + delay 78 + "] supplied to monitor"); 79 return; 80 } else if (delay == 0) { 81 wait(); 82 } else { 83 wait(delay); 84 } 85 } catch (Exception ex) { 86 log.error("The monitor exited abnormally because : " + 87 ex.getMessage(),ex); 88 } 89 } 90 91 92 96 public synchronized void notifyProcessor() { 97 notify(); 98 } 99 100 101 104 public synchronized void terminate() { 105 terminated = true; 106 notify(); 107 } 108 109 } 110 | Popular Tags |