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.ResourceLimitingPool; 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.thread.ThreadControl; 29 import org.apache.excalibur.thread.ThreadPool; 30 31 42 public class ResourceLimitingThreadPool 43 extends ThreadGroup 44 implements ObjectFactory, LogEnabled, Disposable, ThreadPool 45 { 46 private ResourceLimitingPool m_underlyingPool; 47 48 51 private BasicThreadPool m_pool; 52 53 56 57 62 public ResourceLimitingThreadPool( final int max ) 63 { 64 this( "Worker Pool", max ); 65 } 66 67 76 public ResourceLimitingThreadPool( final String name, final int max ) 77 { 78 this( name, max, true, true, 0, 10000 ); 79 } 80 81 98 public ResourceLimitingThreadPool( final String name, 99 final int max, 100 final boolean maxStrict, 101 final boolean blocking, 102 final long blockTimeout, 103 final long trimInterval ) 104 { 105 super( name ); 106 107 m_underlyingPool = 108 new ResourceLimitingPool( this, max, maxStrict, 109 blocking, blockTimeout, 110 trimInterval ); 111 try 112 { 113 m_pool = new BasicThreadPool( this, name, m_underlyingPool ); 114 } 115 catch( Exception e ) 116 { 117 final String message = "Unable to create ThreadPool due to " + e; 118 throw new IllegalStateException ( message ); 119 } 120 } 121 122 127 public int getSize() 128 { 129 return m_underlyingPool.getSize(); 130 } 131 132 public void enableLogging( final Logger logger ) 133 { 134 ContainerUtil.enableLogging( m_pool, logger ); 135 } 136 137 public void dispose() 138 { 139 m_pool.dispose(); 140 } 141 142 public Object newInstance() 143 { 144 return m_pool.newInstance(); 145 } 146 147 public void decommission( final Object object ) 148 { 149 m_pool.decommission( object ); 150 } 151 152 public Class getCreatedClass() 153 { 154 return m_pool.getCreatedClass(); 155 } 156 157 164 public ThreadControl execute( final Executable work ) 165 { 166 return m_pool.execute( work ); 167 } 168 169 176 public ThreadControl execute( final Runnable work ) 177 { 178 return m_pool.execute( work ); 179 } 180 181 188 public ThreadControl execute( final org.apache.excalibur.thread.Executable work ) 189 { 190 return m_pool.execute( work ); 191 } 192 } 193 | Popular Tags |