1 /*
2 * Copyright (C) The Spice Group. All rights reserved.
3 *
4 * This software is published under the terms of the Spice
5 * Software License version 1.1, a copy of which has been included
6 * with this distribution in the LICENSE.txt file.
7 */
8 package org.jcomponent.threadpool.impl;
9
10 import org.apache.commons.pool.impl.GenericObjectPool;
11
12 /***
13 * The PicoCommonsThreadPool wraps the CommonsThreadPool for
14 * Pico-compatible systems.
15 *
16 * @author <a href="mailto:peter at realityforge.org">Peter Donald</a>
17 * @version $Revision: 1.7 $ $Date: 2003/09/02 08:07:29 $
18 */
19 public class PicoCommonsThreadPool
20 extends CommonsThreadPool
21 {
22 public static class Default
23 extends PicoCommonsThreadPool
24 {
25 public Default()
26 {
27 super( new NullThreadPoolMonitor(),
28 "Default ThreadPool",
29 Thread.NORM_PRIORITY,
30 false,
31 false,
32 10,
33 5 );
34 }
35 }
36
37 public static class WithMonitor
38 extends PicoCommonsThreadPool
39 {
40 public WithMonitor( final ThreadPoolMonitor monitor )
41 {
42 super( monitor,
43 "Default ThreadPool",
44 Thread.NORM_PRIORITY,
45 false,
46 false,
47 10,
48 5 );
49 }
50 }
51
52 public static class WithMonitorAndConfig
53 extends PicoCommonsThreadPool
54 {
55 public WithMonitorAndConfig( final ThreadPoolMonitor monitor,
56 final String name,
57 final int priority,
58 final boolean isDaemon,
59 final boolean limited,
60 final int maxActiveThreads,
61 final int maxIdleThreads )
62 {
63 super( monitor, name, priority, isDaemon, limited, maxActiveThreads, maxIdleThreads );
64 }
65 }
66
67 /***
68 * Constructor
69 *
70 */
71 protected PicoCommonsThreadPool( final ThreadPoolMonitor monitor,
72 final String name,
73 final int priority,
74 final boolean isDaemon,
75 final boolean limited,
76 final int maxActiveThreads,
77 final int maxIdleThreads )
78 {
79 setMonitor( monitor );
80 setName( name );
81 setPriority( priority );
82 setDaemon( isDaemon );
83
84 final GenericObjectPool.Config config = getCommonsConfig();
85 if( limited )
86 {
87 config.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_BLOCK;
88 }
89 else
90 {
91 config.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_GROW;
92 }
93
94 config.maxActive = maxActiveThreads;
95 config.maxIdle = maxIdleThreads;
96 setup();
97 }
98
99 /***
100 * Make sure that finalize results in disposal
101 * of the system.
102 */
103 protected void finalize()
104 {
105 shutdown();
106 }
107 }
This page was automatically generated by Maven