1 17 package org.apache.avalon.excalibur.thread.impl; 18 19 import org.apache.avalon.excalibur.pool.ObjectFactory; 20 import org.apache.avalon.excalibur.pool.InstrumentedResourceLimitingPool; 21 22 import org.apache.avalon.framework.activity.Disposable; 23 import org.apache.avalon.framework.activity.Executable; 24 import org.apache.avalon.framework.container.ContainerUtil; 25 import org.apache.avalon.framework.logger.LogEnabled; 26 import org.apache.avalon.framework.logger.Logger; 27 28 import org.apache.excalibur.instrument.Instrument; 29 import org.apache.excalibur.instrument.Instrumentable; 30 31 import org.apache.excalibur.thread.ThreadControl; 32 import org.apache.excalibur.thread.ThreadPool; 33 34 44 public class InstrumentedResourceLimitingThreadPool 45 extends ThreadGroup 46 implements ObjectFactory, LogEnabled, Disposable, ThreadPool, Instrumentable 47 { 48 private InstrumentedResourceLimitingPool m_underlyingPool; 49 50 51 private String m_instrumentableName; 52 53 56 private BasicThreadPool m_pool; 57 58 61 62 67 public InstrumentedResourceLimitingThreadPool( final int max ) 68 { 69 this( "Worker Pool", max ); 70 } 71 72 81 public InstrumentedResourceLimitingThreadPool( final String name, final int max ) 82 { 83 this( name, max, true, true, 0, 10000 ); 84 } 85 86 103 public InstrumentedResourceLimitingThreadPool( final String name, 104 final int max, 105 final boolean maxStrict, 106 final boolean blocking, 107 final long blockTimeout, 108 final long trimInterval ) 109 { 110 super( name ); 111 112 m_underlyingPool = 113 new InstrumentedResourceLimitingPool( this, max, maxStrict, 114 blocking, blockTimeout, 115 trimInterval ); 116 try 117 { 118 m_pool = new BasicThreadPool( this, name, m_underlyingPool ); 119 } 120 catch( Exception e ) 121 { 122 final String message = "Unable to create ThreadPool due to " + e; 123 throw new IllegalStateException ( message ); 124 } 125 } 126 127 130 143 public void setInstrumentableName( String name ) 144 { 145 m_instrumentableName = name; 146 } 147 148 153 public String getInstrumentableName() 154 { 155 return m_instrumentableName; 156 } 157 158 169 public Instrument[] getInstruments() 170 { 171 return Instrumentable.EMPTY_INSTRUMENT_ARRAY; 172 } 173 174 183 public Instrumentable[] getChildInstrumentables() 184 { 185 return new Instrumentable[]{m_underlyingPool}; 186 } 187 188 193 public int getSize() 194 { 195 return m_underlyingPool.getSize(); 196 } 197 198 public void enableLogging( final Logger logger ) 199 { 200 ContainerUtil.enableLogging( m_pool, logger ); 201 } 202 203 public void dispose() 204 { 205 m_pool.dispose(); 206 } 207 208 public Object newInstance() 209 { 210 return m_pool.newInstance(); 211 } 212 213 public void decommission( final Object object ) 214 { 215 m_pool.decommission( object ); 216 } 217 218 public Class getCreatedClass() 219 { 220 return m_pool.getCreatedClass(); 221 } 222 223 230 public ThreadControl execute( final Executable work ) 231 { 232 return m_pool.execute( work ); 233 } 234 235 242 public ThreadControl execute( final Runnable work ) 243 { 244 return m_pool.execute( work ); 245 } 246 247 254 public ThreadControl execute( final org.apache.excalibur.thread.Executable work ) 255 { 256 return m_pool.execute( work ); 257 } 258 } 259 | Popular Tags |