KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > cornerstone > blocks > threads > ResourceLimitingThreadManager


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12  * implied.
13  *
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.avalon.cornerstone.blocks.threads;
19
20 import java.util.Map JavaDoc;
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 /**
26  * Implementation of ResourceLimitingThreadManager.
27  *
28  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
29  * @avalon.component name="limiting-thread-manager" lifestyle="singleton"
30  * @avalon.service type="org.apache.avalon.cornerstone.services.threads.ThreadManager"
31  */

32 public class ResourceLimitingThreadManager
33     extends AbstractThreadManager
34 {
35     protected void configureThreadPool( final Map JavaDoc threadPools,
36                                         final Configuration configuration )
37         throws ConfigurationException
38     {
39         final String JavaDoc 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 JavaDoc e )
57         {
58             final String JavaDoc message = "Error creating ThreadPool named " + name;
59             throw new ConfigurationException( message, e );
60         }
61     }
62 }
63
Popular Tags