01: package com.sun.portal.proxylet.client.common.server.util;
02:
03: import java.util.*;
04:
05: public class ThreadPool implements Cleanable {
06: private String name;
07:
08: private Vector pool = new Vector();
09:
10: public ThreadPool(String name) {
11: this .name = name;
12: }
13:
14: public synchronized ReusableThread get() {
15: ReusableThread rt = null;
16:
17: if (pool.size() > 0) {
18: rt = (ReusableThread) pool.firstElement();
19: pool.removeElement(rt);
20: }
21:
22: if (rt == null) {
23: rt = new ReusableThread(this );
24: rt.start();
25: }
26:
27: return rt;
28: }
29:
30: public synchronized void put(ReusableThread rt) {
31: pool.addElement(rt);
32: }
33:
34: public synchronized void clean() {
35: long now = System.currentTimeMillis();
36:
37: for (Enumeration e = pool.elements(); e.hasMoreElements();) {
38: ReusableThread rt = (ReusableThread) e.nextElement();
39: if (now - rt.getLastRunTime() >= 30000) {
40: rt.terminate();
41: pool.removeElement(rt);
42: }
43: }
44: }
45: }
|