📄 threadpool.java
字号:
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi
// Source File Name: ThreadPool.java
package syi.util;
public class ThreadPool extends Thread
{
private static Object lock = new Object();
private static int threadLimit = 0;
private static int priority = 1;
private static ThreadPool pool[] = null;
private int poolNumber;
private boolean isLive;
private boolean isEmpty;
private Runnable runnable;
private ThreadPool(Runnable runnable1, String s, int i)
{
super(s);
isLive = true;
isEmpty = false;
runnable = null;
poolNumber = i;
runnable = runnable1;
setPriority(priority);
setDaemon(true);
start();
}
protected void finalize()
throws Throwable
{
super.finalize();
kill();
}
public static int getCountOfSleeping()
{
int i = 0;
synchronized(lock)
{
if(pool == null)
return 0;
for(int j = 0; j < pool.length; j++)
{
ThreadPool threadpool = pool[j];
i += threadpool != null && threadpool.isEmpty ? 1 : 0;
}
}
return i;
}
public static int getCountOfWorking()
{
int i = 0;
synchronized(lock)
{
if(pool == null)
return 0;
for(int j = 0; j < pool.length; j++)
{
ThreadPool threadpool = pool[j];
i += threadpool != null && !threadpool.isEmpty ? 1 : 0;
}
}
return i;
}
public void interrupt()
{
try
{
if(isEmpty)
return;
super.interrupt();
}
catch(Throwable throwable)
{
throwable.printStackTrace();
}
}
private void kill()
{
if(pool == null)
return;
if(!isLive)
return;
isLive = false;
try
{
synchronized(lock)
{
pool[poolNumber] = null;
}
runnable = null;
super.interrupt();
}
catch(RuntimeException _ex) { }
catch(ThreadDeath _ex) { }
}
public static void poolGcAll()
{
if(pool == null)
return;
synchronized(lock)
{
for(int i = 0; i < pool.length; i++)
{
ThreadPool threadpool = pool[i];
if(threadpool != null && threadpool.isEmpty)
threadpool.kill();
}
}
}
public static void poolKillAll()
{
if(pool == null)
return;
synchronized(lock)
{
for(int i = 0; i < pool.length; i++)
pool[i].kill();
}
}
public static void poolSetLimit(int i)
{
synchronized(lock)
{
poolKillAll();
threadLimit = i;
pool = new ThreadPool[i > 0 ? threadLimit : 25];
}
}
public static void poolStartThread(Runnable runnable1, char c)
{
poolStartThread(runnable1, String.valueOf(c));
}
public static ThreadPool poolStartThread(Runnable runnable1, String s)
{
if(s == null || s.length() <= 0)
s = "pool";
try
{
synchronized(lock)
{
if(pool == null)
poolSetLimit(threadLimit);
int i = pool.length;
for(int j = 0; j < i; j++)
{
ThreadPool threadpool = pool[j];
if(threadpool == null || !threadpool.isEmpty)
continue;
if(threadpool.restart(runnable1, s))
return threadpool;
threadpool.kill();
}
for(int k = 0; k < i; k++)
{
if(pool[k] != null)
continue;
pool[k] = new ThreadPool(runnable1, s, k);
return pool[k];
}
if(threadLimit <= 0)
{
ThreadPool athreadpool[] = new ThreadPool[i + Math.min(Math.max((int)((double)i * 0.40000000000000002D), 1), 100)];
for(int l = 0; l < i; l++)
athreadpool[l] = pool[l];
pool = athreadpool;
pool[i] = new ThreadPool(runnable1, s, i);
return pool[i];
}
}
}
catch(RuntimeException runtimeexception)
{
runtimeexception.printStackTrace();
}
return null;
}
private boolean restart(Runnable runnable1, String s)
{
try
{
if(!isLive)
{
return false;
} else
{
runnable = runnable1;
isEmpty = false;
setName(s);
super.interrupt();
return true;
}
}
catch(RuntimeException _ex)
{
return false;
}
}
public void run()
{
while(isLive)
{
run2();
try
{
if(!isLive)
break;
isEmpty = true;
Thread.sleep(0x1b7740L);
continue;
}
catch(InterruptedException _ex)
{
Thread.interrupted();
continue;
}
catch(Throwable _ex) { }
break;
}
kill();
}
private void run2()
{
try
{
if(runnable != null)
runnable.run();
}
catch(Throwable _ex) { }
runnable = null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -