|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| package org.jconfig.server; |
|
8 |
| |
|
9 |
| import java.util.Vector; |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| public class ThreadPool { |
|
15 |
| |
|
16 |
| private Vector threadPool; |
|
17 |
| private int maxSize = 50; |
|
18 |
| private int counter = 0; |
|
19 |
| private ThreadGroup tg; |
|
20 |
| private String threadName; |
|
21 |
| |
|
22 |
0
| public ThreadPool() {
|
|
23 |
0
| threadPool = new Vector();
|
|
24 |
0
| tg = new ThreadGroup("SERVER THREAD POOL");
|
|
25 |
0
| threadName = "TP-ANON";
|
|
26 |
0
| for ( int i = 0; i < maxSize; i++) {
|
|
27 |
0
| try {
|
|
28 |
| |
|
29 |
| |
|
30 |
0
| WorkerThread wt = new WorkerThread(tg,threadName);
|
|
31 |
0
| threadPool.add(wt);
|
|
32 |
| } |
|
33 |
| catch (Exception e) { |
|
34 |
0
| e.printStackTrace();
|
|
35 |
| } |
|
36 |
| } |
|
37 |
| } |
|
38 |
| |
|
39 |
0
| public WorkerThread getWorker() {
|
|
40 |
| |
|
41 |
0
| WorkerThread wt = (WorkerThread)threadPool.get(0);
|
|
42 |
0
| threadPool.remove(0);
|
|
43 |
0
| return wt;
|
|
44 |
| } |
|
45 |
| |
|
46 |
0
| public void releaseWorkerThread(WorkerThread wt) {
|
|
47 |
0
| counter --;
|
|
48 |
0
| threadPool.insertElementAt(wt, threadPool.size());
|
|
49 |
| } |
|
50 |
| |
|
51 |
| |
|
52 |
| } |