KickJava   Java API By Example, From Geeks To Geeks.

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


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
22 import org.apache.avalon.excalibur.thread.impl.DefaultThreadPool;
23
24 import org.apache.avalon.framework.configuration.Configuration;
25 import org.apache.avalon.framework.configuration.ConfigurationException;
26
27 /**
28  * Default implementation of ThreadManager.
29  *
30  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
31  *
32  * @avalon.component name="thread-manager" lifestyle="singleton"
33  * @avalon.service type="org.apache.avalon.cornerstone.services.threads.ThreadManager"
34  */

35 public class DefaultThreadManager
36     extends AbstractThreadManager
37 {
38     protected void configureThreadPool( final Map JavaDoc threadPools,
39                                         final Configuration configuration )
40         throws ConfigurationException
41     {
42         final String JavaDoc name = configuration.getChild( "name" ).getValue();
43         // NEVER USED!!
44
//final int priority = configuration.getChild( "priority" ).getValueAsInteger( 5 );
45
final boolean isDaemon = configuration.getChild( "is-daemon" ).getValueAsBoolean( false );
46
47         final int minThreads = configuration.getChild( "min-threads" ).getValueAsInteger( 5 );
48         final int maxThreads = configuration.getChild( "max-threads" ).getValueAsInteger( 10 );
49
50         // NEVER USED!!
51
//final int minSpareThreads = configuration.getChild( "min-spare-threads" ).
52
// getValueAsInteger( maxThreads - minThreads );
53

54         try
55         {
56             final DefaultThreadPool threadPool =
57                 new DefaultThreadPool( name, minThreads, maxThreads );
58             threadPool.setDaemon( isDaemon );
59             threadPool.enableLogging( getLogger() );
60             threadPools.put( name, threadPool );
61         }
62         catch( final Exception JavaDoc e )
63         {
64             final String JavaDoc message = "Error creating ThreadPool named " + name;
65             throw new ConfigurationException( message, e );
66         }
67     }
68 }
69
Popular Tags