1 17 18 package org.apache.avalon.cornerstone.blocks.threads; 19 20 import java.util.Map ; 21 import org.apache.avalon.excalibur.thread.impl.ResourceLimitingThreadPool; 22 import org.apache.avalon.framework.configuration.Configuration; 23 import org.apache.avalon.framework.configuration.ConfigurationException; 24 25 32 public class ResourceLimitingThreadManager 33 extends AbstractThreadManager 34 { 35 protected void configureThreadPool( final Map threadPools, 36 final Configuration configuration ) 37 throws ConfigurationException 38 { 39 final String name = configuration.getChild( "name" ).getValue(); 40 final boolean isDaemon = configuration.getChild( "is-daemon" ).getValueAsBoolean( false ); 41 42 final int max = configuration.getChild( "max-threads" ).getValueAsInteger( 10 ); 43 final boolean maxStrict = configuration.getChild( "max-strict" ).getValueAsBoolean( true ); 44 final boolean blocking = configuration.getChild( "blocking" ).getValueAsBoolean( true ); 45 final long blockTimeout = configuration.getChild( "block-timeout" ).getValueAsLong( 0 ); 46 final long trimInterval = configuration.getChild( "trim-interval" ).getValueAsLong( 10000 ); 47 48 try 49 { 50 final ResourceLimitingThreadPool threadPool = new ResourceLimitingThreadPool( 51 name, max, maxStrict, blocking, blockTimeout, trimInterval ); 52 threadPool.setDaemon( isDaemon ); 53 threadPool.enableLogging( getLogger() ); 54 threadPools.put( name, threadPool ); 55 } 56 catch( final Exception e ) 57 { 58 final String message = "Error creating ThreadPool named " + name; 59 throw new ConfigurationException( message, e ); 60 } 61 } 62 } 63 | Popular Tags |