-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathThreadPool.html
More file actions
349 lines (343 loc) · 29.1 KB
/
Copy pathThreadPool.html
File metadata and controls
349 lines (343 loc) · 29.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
<!DOCTYPE HTML PUBLIC "-//w3c//dtd html 4.0 transitional//en" "http://www.w3.org/TR/REC-html40/loose.dtd">
<!--
Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0 which is available at
http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
v. 1.0 which is available at
http://www.eclipse.org/org/documents/edl-v10.php.
This Source Code may also be made available under the following Secondary
Licenses when the conditions for such availability set forth in the Eclipse
Public License v. 2.0 are satisfied: GNU General Public License v2.0
w/Classpath exception which is available at
https://www.gnu.org/software/classpath/license.html.
SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause OR GPL-2.0 WITH
Classpath-exception-2.0
-->
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Author" CONTENT="Dhiru Pandey">
<META NAME="GENERATOR"
CONTENT="Mozilla/4.79 [en] (Windows NT 5.0; U) [Netscape]">
<TITLE>ThreadPool Element in Server.xml</TITLE>
</HEAD>
<BODY BACKGROUND="images/backgrounds/p12c08.gif">
<H1> ThreadPool Configuration in the Application Server</H1>
<H2> Introduction</H2> Based on discussions and collective agreement, it is
felt that the ThreadPool should really be a separate element in the server.xml
instead of getting bundled in with the ORB element as it exists today in S1AS
7.0.
<P>This document describes why this is useful to do and how this could be
achieved. </P>
<H2> ThreadPool configuration and DTD</H2> If ThreadPool was made a
separate element in the server.xml it would allow the user to configure more
than one ThreadPools (if required) and associate these threadpools to other
components of the Application Server (ORB, Connectors etc.). This would
encourage code re-use as well as give the user controls to tune the Application
Server based on the load in the system and in different sub-systems (ORB,
Connectors etc.). Inherent advantages offered by this scheme:
<UL>
<LI> One single place for the user to specify different threadpools
configuration params</LI>
<LI> Ability to have multiple threadpools. This will aid in starvation
problems and help improve performace (ECPerf)</LI>
<LI> Ability to dedicate threadpools/work-queues to App. server
components and EJB beans if desired.</LI>
<LI> Allow monitoring and administration on the
threadpool/work-queues</LI>
</UL> The DTD given below describes the ThreadPool configuration element.
This element would be at the same level as the other components like
http-service, iiop-service, web-container, ejb-container etc. in the S1AS 8.0
server.xml DTD (<A
HREF="http://iaseng.red.iplanet.com/apollo/config/sun-server_8_0.dtd">http://iaseng.red.iplanet.com/apollo/config/sun-server_8_0.dtd</A>):
<BR>
<P><FONT COLOR="#000099"><!ELEMENT thread-pool-config
(thread-pool+)></FONT> </P>
<P><FONT COLOR="#000099"><!--</FONT> <BR><FONT
COLOR="#000099">
thread-pool-id
This is an id for the work-queue e.g. "thread-pool-1", "thread-pool-2"
etc</FONT> <BR><FONT COLOR="#000099">
min-thread-pool-size
Minimum number of threads in the threadpool servicing requests in this
queue.</FONT> <BR><FONT
COLOR="#000099">
These are created up front when this threadpool is instantiated</FONT>
<BR><FONT COLOR="#000099">
max-thread-pool-size
Maximum number of threads in the threadpool servicing requests in this
queue</FONT> <BR><FONT
COLOR="#000099">
This is the upper bound on the no. of threads that exist in the
threadpool.</FONT> <BR><FONT COLOR="#000099">
idle-thread-timeout-in-seconds idle threads are
removed from pool, after this time</FONT> <BR><FONT
COLOR="#000099">
num-work-queues
This denotes the total number of work queues that are serviced by this
threadpool.</FONT> <BR><FONT
COLOR="#000099">
Default value would be 1</FONT> <BR><FONT COLOR="#000099">--></FONT> </P>
<P><FONT COLOR="#000099"><!ELEMENT thread-pool(EMPTY)></FONT>
<BR><FONT COLOR="#000099"><!ATTLIST thread-pool
thread-pool-id
CDATA #REQUIRED</FONT> <BR><FONT
COLOR="#000099">
min-thread-pool-size
CDATA "0"</FONT> <BR><FONT
COLOR="#000099">
max-thread-pool-size
CDATA "200"</FONT> <BR><FONT
COLOR="#000099">
idle-thread-timeout-in-seconds CDATA "120"</FONT>
<BR><FONT
COLOR="#000099">
num-work-queues
CDATA "1"></FONT> </P>
<P><FONT COLOR="#000099"><!-- The ORB element would look like
...</FONT> </P>
<P><FONT COLOR="#000099">
use-thread-pool-ids
This would refer to the thread-pool-id(s) defined in the thread-pool
sub-element of</FONT> <BR><FONT
COLOR="#000099">
thread-pool-config element in server.xml. These would be the threadpool(s) used
by the</FONT> <BR><FONT
COLOR="#000099">
ORB. More than one thread-pool-id(s) could be specified by using commas to
separate</FONT> <BR><FONT
COLOR="#000099">
the names e.g. "orb-thread-pool-1, orb-thread-pool-2"</FONT> <BR><FONT
COLOR="#000099">--></FONT> </P>
<P><FONT COLOR="#000099"><!ELEMENT orb (property*)></FONT> <BR><FONT
COLOR="#000099"><!ATTLIST orb
message-fragment-size
CDATA "1024"</FONT> <BR><FONT
COLOR="#000099">
use-thread-pool-ids
IDREFS #REQUIRED</FONT>
<BR><FONT
COLOR="#000099">
max-connections
CDATA "1024"</FONT> <BR><FONT
COLOR="#000099">
....</FONT> <BR><FONT
COLOR="#000099">
...></FONT> </P>
<P>Essentially, thread-pool-config is a server wide element, that consists
of atleast 1 or more thread-pool elements. </P>
<P>A ThreadPoolManagerImpl class could be used as a singleton instance, to
create all the ThreadPools at server startup using the configuration parameters
defined in the threadpool-config element of the server.xml. Any component can
then get the threadpool instance by providing the threadpool-id to this
singleton ThreadPoolManager instance. Using this threadpool instance a work
queue serviced by this threadpool can be obtained. Work can be added to the
queue and it will get processed by the threads of the threadpool. </P>
<P>EJB descriptors (or module descriptors - not sure if there is anything
like this) could use the threadpool-ids defined in the server.xml to denote if
the EJB (module) would want to use a dedicated threadpool. This could be done
to avoid starvation. If nothing is specified or incorrect threadpool-id is
specified in the bean descriptors, then the threadpool associated with the ORB
will be used to service requests from that bean. <BR> <BR> </P>
<H2> ThreadPoolManager SPI</H2> This section defines the ThreadPoolManager
SPI. This SPI will be defined in com.sun.corba.ee.spi....(the exact package
name is TBD)
<P>This interface will be implemented by the ThreadPoolManagerImpl class in
App. Server PE 8.0. It will be responsible for returning an instance of the
ThreadPool given a thread-pool-id, from any component that wants to use a
ThreadPool. In addition, ThreadPoolManagerImpl class will be responsible for
creating all the threadpools (and their queues) at server startup time. This is
done using the config bean that reads the thread-pool-config element in
server.xml. ThreadPoolManager instance would be a singleton instance in the
App. Server process. <BR> </P>
<P><B><FONT COLOR="#009900">public interface ThreadPoolManager {</FONT></B>
</P>
<P><B><FONT COLOR="#009900"> </FONT><FONT
COLOR="#666666">/**</FONT></B> <BR><B><FONT COLOR="#666666">
* This method will return an instance of the threadpool given a
threadpoolId,</FONT></B> <BR><B><FONT COLOR="#666666"> * that
can be used by any component in the app. server.</FONT></B> <BR><B><FONT
COLOR="#666666"> */</FONT></B> <BR><B><FONT
COLOR="#009900"> public ThreadPool getThreadPool(String
threadpoolId);</FONT></B> </P>
<P><B><FONT COLOR="#009900"> </FONT><FONT
COLOR="#666666">/**</FONT></B> <BR><B><FONT COLOR="#666666">
* This method will return an instance of the threadpool given a numeric
threadpoolId.</FONT></B> <BR><B><FONT COLOR="#666666"> * This
method will be used by the ORB to support the functionality of</FONT></B>
<BR><B><FONT COLOR="#666666"> * dedicated threadpool for EJB
beans</FONT></B> <BR><B><FONT COLOR="#666666"> */</FONT></B>
<BR><B><FONT COLOR="#009900"> public ThreadPool
getThreadPool(int numericIdForThreadpool);</FONT></B> </P>
<P><B><FONT COLOR="#009900"> </FONT><FONT
COLOR="#666666">/**</FONT></B> <BR><B><FONT COLOR="#666666">
* This method is used to return the numeric id of the threadpool, given a
String</FONT></B> <BR><B><FONT COLOR="#666666"> *
threadpoolId. This is used by the POA interceptors to add the numeric
threadpool</FONT></B> <BR><B><FONT COLOR="#666666"> * Id, as
a tagged component in the IOR. This is used to provide the functionality
of</FONT></B> <BR><B><FONT COLOR="#666666"> * dedicated
threadpool for EJB beans</FONT></B> <BR><B><FONT
COLOR="#666666"> */</FONT></B> <BR><B><FONT
COLOR="#009900"> public int getNumericId(String
threadpoolId);</FONT></B> </P>
<P><B><FONT COLOR="#009900"> </FONT><FONT
COLOR="#666666">/**</FONT></B> <BR><B><FONT COLOR="#666666">
* Return a String Id for a numericId of a threadpool managed by the
threadpool</FONT></B> <BR><B><FONT COLOR="#666666"> *
manager</FONT></B> <BR><B><FONT COLOR="#666666">
*/</FONT></B> <BR><B><FONT COLOR="#009900"> public String
getStringId(int numericIdForThreadpool);</FONT></B> </P>
<P><B><FONT COLOR="#009900"> </FONT><FONT
COLOR="#666666">/**</FONT></B> <BR><B><FONT COLOR="#666666">
* Returns the first instance of ThreadPool in the ThreadPoolManager</FONT></B>
<BR><B><FONT COLOR="#666666"> */</FONT></B> <BR><B><FONT
COLOR="#009900"> public ThreadPool
getDefaultThreadPool();</FONT></B> </P>
<P><B><FONT COLOR="#009900">}</FONT></B> </P>
<P>An implementation of this SPI will also exist in the ORB that ships with
J2SE, so that the ORB code that uses these API does not change for J2SE.
<BR> </P>
<H2> ThreadPool SPI</H2> This section defines the ThreadPool SPI. This SPI
will be defined in com.sun.corba.ee.spi....(the exact package name is TBD)
<P>The ORB already has plans for having an interface like that as part of
the work being done on the design of the ORB transport. I am adding more APIs
to the designed interface for this done by Harold Carr. </P>
<P><B><FONT COLOR="#009900">public interface ThreadPool {</FONT></B> </P>
<P><B><FONT COLOR="#009900"> </FONT><FONT
COLOR="#666666">/**</FONT></B> <BR><B><FONT COLOR="#666666">
* This method will return any instance of the WorkQueue. If the
ThreadPool</FONT></B> <BR><B><FONT COLOR="#666666"> *
instance only services one WorkQueue then that WorkQueue instance
will</FONT></B> <BR><B><FONT COLOR="#666666"> * be returned.
If there are more than one WorkQueues serviced by this</FONT></B> <BR><B><FONT
COLOR="#666666"> * ThreadPool, then this method would return
a WorkQueue based on the</FONT></B> <BR><B><FONT
COLOR="#666666"> * implementation of the class that
implements this interface. For PE 8.0 we</FONT></B> <BR><B><FONT
COLOR="#666666"> * would return a WorkQueue in a roundrobin
fashion everytime this method</FONT></B> <BR><B><FONT
COLOR="#666666"> * is called. In the future we could allow
pluggability of Policy objects for this.</FONT></B> <BR><B><FONT
COLOR="#666666"> */</FONT></B> <BR><B><FONT
COLOR="#009900"> public WorkQueue
getAnyWorkQueue();</FONT></B> </P>
<P><B><FONT COLOR="#009900"> </FONT><FONT
COLOR="#666666">/**</FONT></B> <BR><B><FONT COLOR="#666666">
* This method will return an instance of the of the WorkQueue given a
queueId.</FONT></B> <BR><B><FONT COLOR="#666666"> * This will
be useful in situations where there are more than one WorkQueues</FONT></B>
<BR><B><FONT COLOR="#666666"> * managed by the ThreadPool and
the user of the ThreadPool wants to always use</FONT></B> <BR><B><FONT
COLOR="#666666"> * the same WorkQueue for doing the
Work.</FONT></B> <BR><B><FONT COLOR="#666666"> * If the
number of WorkQueues in the ThreadPool are 10, then queueIds will go</FONT></B>
<BR><B><FONT COLOR="#666666"> * from 0-9</FONT></B>
<BR><B><FONT COLOR="#666666"> */</FONT></B> <BR><B><FONT
COLOR="#009900"> public WorkQueue getWorkQueue(int
queueId);</FONT></B> </P>
<P><B><FONT COLOR="#009900"> </FONT><FONT
COLOR="#666666">/**</FONT></B> <BR><B><FONT COLOR="#666666">
* This method will return the number of WorkQueues serviced by the
threadpool.</FONT></B> <BR><B><FONT COLOR="#666666">
*/</FONT></B> <BR><B><FONT COLOR="#009900"> public int
numberOfWorkQueues();</FONT></B> </P>
<P><B><FONT COLOR="#009900"> </FONT><FONT
COLOR="#666666">/**</FONT></B> <BR><B><FONT COLOR="#666666">
* This method will return the minimum number of threads maintained by the
threadpool.</FONT></B> <BR><B><FONT COLOR="#666666">
*/</FONT></B> <BR><B><FONT COLOR="#009900"> public int
minimumNumberOfThreads();</FONT></B> </P>
<P><B><FONT COLOR="#009900"> </FONT><FONT
COLOR="#666666">/**</FONT></B> <BR><B><FONT COLOR="#666666">
* This method will return the maximum number of threads in the threadpool at
any</FONT></B> <BR><B><FONT COLOR="#666666"> * point in time,
for the life of the threadpool</FONT></B> <BR><B><FONT
COLOR="#666666"> */</FONT></B> <BR><B><FONT
COLOR="#009900"> public int
maximumNumberOfThreads();</FONT></B> </P>
<P><B><FONT COLOR="#009900"> </FONT><FONT
COLOR="#666666">/**</FONT></B> <BR><B><FONT COLOR="#666666">
* This method will return the time in milliseconds when idle threads in the
threadpool are</FONT></B> <BR><B><FONT COLOR="#666666"> *
removed.</FONT></B> <BR><B><FONT COLOR="#666666">
*/</FONT></B> <BR><B><FONT COLOR="#009900"> public long
idleTimeoutForThreads();</FONT></B> </P>
<P><B><FONT COLOR="#009900"> </FONT><FONT
COLOR="#666666">/**</FONT></B> <BR><B><FONT COLOR="#666666">
* This method will return the current number of threads in the threadpool. This
method</FONT></B> <BR><B><FONT COLOR="#666666"> * returns a
value which is not synchronized.</FONT></B> <BR><B><FONT
COLOR="#666666"> */</FONT></B> <BR><B><FONT
COLOR="#009900"> public int
currentNumberOfThreads();</FONT></B> </P>
<P><B><FONT COLOR="#009900"> </FONT><FONT
COLOR="#666666">/**</FONT></B> <BR><B><FONT COLOR="#666666">
* This method will return the number of available threads in the threadpool
which are</FONT></B> <BR><B><FONT COLOR="#666666"> *
waiting for work. This method returns a value which is not
synchronized.</FONT></B> <BR><B><FONT COLOR="#666666">
*/</FONT></B> <BR><B><FONT COLOR="#009900"> public int
numberOfAvailableThreads();</FONT></B> </P>
<P><B><FONT COLOR="#009900"> </FONT><FONT
COLOR="#666666">/**</FONT></B> <BR><B><FONT COLOR="#666666">
* This method will return the number of busy threads in the
threadpool</FONT></B> <BR><B><FONT COLOR="#666666"> * This
method returns a value which is not synchronized.</FONT></B> <BR><B><FONT COLOR="#666666">
*/</FONT></B> <BR><B><FONT COLOR="#009900"> public int
numberOfBusyThreads();</FONT></B> </P>
<P><B><FONT COLOR="#009900"> </FONT><FONT
COLOR="#666666">/**</FONT></B> <BR><B><FONT COLOR="#666666">
* This method returns the number of Work items processed by the
threadpool</FONT></B> <BR><B><FONT COLOR="#666666">
*/</FONT></B> <BR><B><FONT COLOR="#009900"> public long
currentProcessedCount();</FONT></B> </P>
<P><B><FONT COLOR="#009900"> </FONT><FONT
COLOR="#666666">/**</FONT></B> <BR><B><FONT COLOR="#666666">
* This method will return the name of the threadpool.</FONT></B> <BR><B><FONT
COLOR="#666666"> */</FONT></B> <BR><B><FONT
COLOR="#009900"> public String getName();</FONT></B> </P>
<P><B><FONT COLOR="#009900">}</FONT></B> <BR> </P>
<H2> WorkQueue SPI</H2> This section defines the WorkQueue SPI. This SPI
will be defined in com.sun.corba.ee.spi....(the exact package name is TBD)
<P>The ORB already has plans for having an interface like that as part of
the work being done on the design of the ORB transport by Harold Carr. The
following has been borrowed from that design </P>
<P><B><FONT COLOR="#009900">public interface WorkQueue {</FONT></B> </P>
<P><B><FONT COLOR="#009900"> </FONT><FONT
COLOR="#666666">/**</FONT></B> <BR><B><FONT COLOR="#666666">
* This method is used to add work to the WorkQueue</FONT></B> <BR><B><FONT
COLOR="#666666"> */</FONT></B> <BR><B><FONT
COLOR="#009900"> public void addWork(Work
aWorkItem);</FONT></B> </P>
<P><B><FONT COLOR="#009900"> </FONT><FONT
COLOR="#666666">/**</FONT></B> <BR><B><FONT COLOR="#666666">
* This method will return the name of the WorkQueue.</FONT></B> <BR><B><FONT
COLOR="#666666"> */</FONT></B> <BR><B><FONT
COLOR="#009900"> public String getName();</FONT></B> </P>
<P><B><FONT COLOR="#009900"> </FONT><FONT
COLOR="#666666">/**</FONT></B> <BR><B><FONT COLOR="#666666">
* Returns the total number of Work items added to the Queue.</FONT></B>
<BR><B><FONT COLOR="#666666"> */</FONT></B> <BR><B><FONT
COLOR="#009900"> public long
totalWorkItemsAdded();</FONT></B><B><FONT COLOR="#009900"></FONT></B> </P>
<P><B><FONT COLOR="#009900"> </FONT><FONT
COLOR="#666666">/**</FONT></B> <BR><B><FONT COLOR="#666666">
* Returns the total number of Work items in the Queue to be
processed.</FONT></B> <BR><B><FONT COLOR="#666666">
*/</FONT></B> <BR><B><FONT COLOR="#009900"> public int
workItemsInQueue();</FONT></B><B><FONT COLOR="#009900"></FONT></B> </P>
<P><B><FONT COLOR="#009900">}</FONT></B> <BR> </P>
<H2> Work SPI</H2> This section defines the Work SPI. This SPI will be
defined in com.sun.corba.ee.spi....(the exact package name is TBD)
<P>The ORB already has plans for having an interface like that as part of
the work being done on the design of the ORB transport by Harold Carr. The
following has been borrowed from that design </P>
<P><B><FONT COLOR="#009900">public interface Work {</FONT></B> </P>
<P><B><FONT COLOR="#009900"> public void
doWork();</FONT></B> </P>
<P><B><FONT COLOR="#009900"> public String
getName();</FONT></B> </P>
<P><B><FONT COLOR="#009900">}</FONT></B> </P></BODY>
</HTML>