1 package org.apache.commons.jcs3.utils.threadpool;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 public final class PoolConfiguration
26 implements Cloneable
27 {
28
29
30
31 private static final boolean DEFAULT_USE_BOUNDARY = true;
32
33
34 private static final int DEFAULT_BOUNDARY_SIZE = 2000;
35
36
37 private static final int DEFAULT_MAXIMUM_POOL_SIZE = 150;
38
39
40 private static final int DEFAULT_MINIMUM_POOL_SIZE = Runtime.getRuntime().availableProcessors();
41
42
43 private static final int DEFAULT_KEEPALIVE_TIME = 1000 * 60 * 5;
44
45
46 private static final WhenBlockedPolicy DEFAULT_WHEN_BLOCKED_POLICY = WhenBlockedPolicy.RUN;
47
48
49 private static final int DEFAULT_STARTUP_SIZE = DEFAULT_MINIMUM_POOL_SIZE;
50
51
52 private boolean useBoundary = DEFAULT_USE_BOUNDARY;
53
54
55 private int boundarySize = DEFAULT_BOUNDARY_SIZE;
56
57
58 private int maximumPoolSize = DEFAULT_MAXIMUM_POOL_SIZE;
59
60
61
62
63
64 private int minimumPoolSize = DEFAULT_MINIMUM_POOL_SIZE;
65
66
67 private int keepAliveTime = DEFAULT_KEEPALIVE_TIME;
68
69 public enum WhenBlockedPolicy {
70
71 ABORT,
72
73
74 BLOCK,
75
76
77 RUN,
78
79
80 WAIT,
81
82
83 DISCARDOLDEST
84 }
85
86
87 private WhenBlockedPolicy whenBlockedPolicy = DEFAULT_WHEN_BLOCKED_POLICY;
88
89
90 private int startUpSize = DEFAULT_MINIMUM_POOL_SIZE;
91
92
93
94
95 public void setUseBoundary( final boolean useBoundary )
96 {
97 this.useBoundary = useBoundary;
98 }
99
100
101
102
103 public boolean isUseBoundary()
104 {
105 return useBoundary;
106 }
107
108
109
110
111 public PoolConfiguration()
112 {
113 this( DEFAULT_USE_BOUNDARY, DEFAULT_BOUNDARY_SIZE, DEFAULT_MAXIMUM_POOL_SIZE,
114 DEFAULT_MINIMUM_POOL_SIZE, DEFAULT_KEEPALIVE_TIME,
115 DEFAULT_WHEN_BLOCKED_POLICY, DEFAULT_STARTUP_SIZE );
116 }
117
118
119
120
121
122
123
124
125
126
127
128
129 public PoolConfiguration( final boolean useBoundary, final int boundarySize, final int maximumPoolSize, final int minimumPoolSize,
130 final int keepAliveTime, final WhenBlockedPolicy whenBlockedPolicy, final int startUpSize )
131 {
132 setUseBoundary( useBoundary );
133 setBoundarySize( boundarySize );
134 setMaximumPoolSize( maximumPoolSize );
135 setMinimumPoolSize( minimumPoolSize );
136 setKeepAliveTime( keepAliveTime );
137 setWhenBlockedPolicy( whenBlockedPolicy );
138 setStartUpSize( startUpSize );
139 }
140
141
142
143
144 public void setBoundarySize( final int boundarySize )
145 {
146 this.boundarySize = boundarySize;
147 }
148
149
150
151
152 public int getBoundarySize()
153 {
154 return boundarySize;
155 }
156
157
158
159
160 public void setMaximumPoolSize( final int maximumPoolSize )
161 {
162 this.maximumPoolSize = maximumPoolSize;
163 }
164
165
166
167
168 public int getMaximumPoolSize()
169 {
170 return maximumPoolSize;
171 }
172
173
174
175
176 public void setMinimumPoolSize( final int minimumPoolSize )
177 {
178 this.minimumPoolSize = minimumPoolSize;
179 }
180
181
182
183
184 public int getMinimumPoolSize()
185 {
186 return minimumPoolSize;
187 }
188
189
190
191
192 public void setKeepAliveTime( final int keepAliveTime )
193 {
194 this.keepAliveTime = keepAliveTime;
195 }
196
197
198
199
200 public int getKeepAliveTime()
201 {
202 return keepAliveTime;
203 }
204
205
206
207
208 public void setWhenBlockedPolicy( final String whenBlockedPolicy )
209 {
210 if ( whenBlockedPolicy != null )
211 {
212 final WhenBlockedPolicy policy = WhenBlockedPolicy.valueOf(whenBlockedPolicy.trim().toUpperCase());
213 setWhenBlockedPolicy(policy);
214 }
215 else
216 {
217
218 this.whenBlockedPolicy = WhenBlockedPolicy.RUN;
219 }
220 }
221
222
223
224
225 public void setWhenBlockedPolicy( final WhenBlockedPolicy whenBlockedPolicy )
226 {
227 if ( whenBlockedPolicy != null )
228 {
229 this.whenBlockedPolicy = whenBlockedPolicy;
230 }
231 else
232 {
233
234 this.whenBlockedPolicy = WhenBlockedPolicy.RUN;
235 }
236 }
237
238
239
240
241 public WhenBlockedPolicy getWhenBlockedPolicy()
242 {
243 return whenBlockedPolicy;
244 }
245
246
247
248
249 public void setStartUpSize( final int startUpSize )
250 {
251 this.startUpSize = startUpSize;
252 }
253
254
255
256
257 public int getStartUpSize()
258 {
259 return startUpSize;
260 }
261
262
263
264
265
266 @Override
267 public String toString()
268 {
269 final StringBuilder buf = new StringBuilder();
270 buf.append( "useBoundary = [" + isUseBoundary() + "] " );
271 buf.append( "boundarySize = [" + boundarySize + "] " );
272 buf.append( "maximumPoolSize = [" + maximumPoolSize + "] " );
273 buf.append( "minimumPoolSize = [" + minimumPoolSize + "] " );
274 buf.append( "keepAliveTime = [" + keepAliveTime + "] " );
275 buf.append( "whenBlockedPolicy = [" + getWhenBlockedPolicy() + "] " );
276 buf.append( "startUpSize = [" + startUpSize + "]" );
277 return buf.toString();
278 }
279
280
281
282
283
284
285 @Override
286 public PoolConfiguration clone()
287 {
288 return new PoolConfiguration( isUseBoundary(), boundarySize, maximumPoolSize, minimumPoolSize, keepAliveTime,
289 getWhenBlockedPolicy(), startUpSize );
290 }
291 }