mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-05-23 13:35:29 +00:00
trunk contents moved to root
This commit is contained in:
53
libsrc/jpproxy/src/com/jpexs/proxy/ThreadPool.java
Normal file
53
libsrc/jpproxy/src/com/jpexs/proxy/ThreadPool.java
Normal file
@@ -0,0 +1,53 @@
|
||||
package com.jpexs.proxy;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class ThreadPool implements Cleanable
|
||||
{
|
||||
private String name;
|
||||
private Vector pool = new Vector();
|
||||
|
||||
public ThreadPool(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public synchronized ReusableThread get()
|
||||
{
|
||||
ReusableThread rt = null;
|
||||
|
||||
if (pool.size() > 0)
|
||||
{
|
||||
rt = (ReusableThread)pool.firstElement();
|
||||
pool.removeElement(rt);
|
||||
}
|
||||
|
||||
if (rt == null)
|
||||
{
|
||||
rt = new ReusableThread(this);
|
||||
rt.start();
|
||||
}
|
||||
|
||||
return rt;
|
||||
}
|
||||
|
||||
public synchronized void put(ReusableThread rt)
|
||||
{
|
||||
pool.addElement(rt);
|
||||
}
|
||||
|
||||
public synchronized void clean()
|
||||
{
|
||||
long now = System.currentTimeMillis();
|
||||
|
||||
for (Enumeration e = pool.elements(); e.hasMoreElements(); )
|
||||
{
|
||||
ReusableThread rt = (ReusableThread) e.nextElement();
|
||||
if (now - rt.getLastRunTime() >= 30000)
|
||||
{
|
||||
rt.terminate();
|
||||
pool.removeElement(rt);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user