1 50 package org.apache.avalon.excalibur.monitor.impl; 51 52 61 public class ActiveMonitor 62 extends AbstractMonitor 63 implements Runnable 64 { 65 private static final long DEFAULT_FREQUENCY = 1000L * 60L; 66 67 71 private long m_frequency = DEFAULT_FREQUENCY; 72 73 77 private int m_priority = Thread.MIN_PRIORITY; 78 79 82 private final Thread m_monitorThread = new Thread ( this ); 83 84 87 private volatile boolean m_keepRunning = true; 88 89 97 public void setFrequency( final long frequency ) 98 { 99 m_frequency = frequency; 100 } 101 102 107 public void setPriority( final int priority ) 108 { 109 m_priority = priority; 110 } 111 112 public void start() 113 throws Exception 114 { 115 m_keepRunning = true; 116 m_monitorThread.setDaemon( true ); 117 m_monitorThread.setPriority( m_priority ); 118 m_monitorThread.start(); 119 } 120 121 public void stop() 122 throws Exception 123 { 124 m_keepRunning = false; 125 m_monitorThread.interrupt(); 126 m_monitorThread.join(); 127 } 128 129 public final void run() 130 { 131 try 132 { 133 while( m_keepRunning ) 134 { 135 Thread.sleep( m_frequency ); 136 scanAllResources(); 137 } 138 } 139 catch( InterruptedException e ) 140 { 141 Thread.interrupted(); 143 } 144 } 145 } 146 | Popular Tags |