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.SoftResourceLimitingPool; 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 36 public class DefaultThreadPool 37 extends ThreadGroup 38 implements ObjectFactory, LogEnabled, Disposable, ThreadPool 39 { 40 private final BasicThreadPool m_pool; 41 private SoftResourceLimitingPool m_underlyingPool; 42 43 public DefaultThreadPool( final int capacity ) 44 throws Exception 45 { 46 this( "Worker Pool", capacity ); 47 } 48 49 public DefaultThreadPool( final String name, 50 final int capacity ) 51 throws Exception 52 { 53 super( name ); 54 m_underlyingPool = new SoftResourceLimitingPool( this, capacity ); 55 m_pool = new BasicThreadPool( this, name, m_underlyingPool ); 56 } 57 58 public DefaultThreadPool( final String name, 59 final int min, 60 final int max ) 61 throws Exception 62 { 63 super( name ); 64 m_underlyingPool = new SoftResourceLimitingPool( this, min, max ); 65 m_pool = new BasicThreadPool( this, name, m_underlyingPool ); 66 } 67 68 public void enableLogging( final Logger logger ) 69 { 70 ContainerUtil.enableLogging( m_pool, logger ); 71 } 72 73 public void dispose() 74 { 75 m_pool.dispose(); 76 } 77 78 public Object newInstance() 79 { 80 return m_pool.newInstance(); 81 } 82 83 public void decommission( final Object object ) 84 { 85 m_pool.decommission( object ); 86 } 87 88 public Class getCreatedClass() 89 { 90 return m_pool.getCreatedClass(); 91 } 92 93 100 public ThreadControl execute( final Executable work ) 101 { 102 return m_pool.execute( work ); 103 } 104 105 112 public ThreadControl execute( final Runnable work ) 113 { 114 return m_pool.execute( work ); 115 } 116 117 124 public ThreadControl execute( final org.apache.excalibur.thread.Executable work ) 125 { 126 return m_pool.execute( work ); 127 } 128 } 129 | Popular Tags |