📄 threadpool.java
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: ThreadPool.java
package org.gudy.azureus2.core3.util;
import com.aelitis.azureus.core.util.Java15Utils;
import java.io.PrintStream;
import java.util.*;
import org.gudy.azureus2.core3.config.COConfigurationManager;
import org.gudy.azureus2.core3.config.ParameterListener;
// Referenced classes of package org.gudy.azureus2.core3.util:
// AEDiagnostics, AERunnable, AESemaphore, Average,
// Debug, DebugLight, DisplayFormatters, IndentWriter,
// SystemTime, ThreadPoolTask, TimeFormatter, AEThread2,
// SimpleTimer, TimerEventPerformer, TimerEvent, AEDiagnosticsEvidenceGenerator
public class ThreadPool
{
class threadPoolWorker extends AEThread2
{
private final String worker_name;
private volatile AERunnable runnable;
private long run_start_time;
private int warn_count;
private String state;
final ThreadPool this$0;
public void run()
{
boolean autoRelease;
ThreadPool.tls.set(this);
autoRelease = true;
_L2:
label0:
{
synchronized (ThreadPool.this)
{
if (task_queue.size() > 0)
{
runnable = (AERunnable)task_queue.remove(0);
break label0;
}
}
break; /* Loop/switch isn't completed */
}
threadpool;
JVM INSTR monitorexit ;
ThreadPoolTask tpt;
String task_name;
synchronized (ThreadPool.this)
{
run_start_time = SystemTime.getCurrentTime();
warn_count = 0;
busy.add(this);
task_total++;
if (busy.size() == 1)
synchronized (ThreadPool.busy_pools)
{
if (!ThreadPool.busy_pools.contains(ThreadPool.this))
{
ThreadPool.busy_pools.add(ThreadPool.this);
if (!ThreadPool.busy_pool_timer_set)
{
COConfigurationManager.addAndFireParameterListeners(new String[] {
"debug.threadpool.log.enable", "debug.threadpool.debug.trace"
}, new ParameterListener() {
final threadPoolWorker this$1;
public void parameterChanged(String name)
{
ThreadPool.debug_thread_pool = COConfigurationManager.getBooleanParameter("debug.threadpool.log.enable", false);
ThreadPool.debug_thread_pool_log_on = COConfigurationManager.getBooleanParameter("debug.threadpool.debug.trace", false);
}
{
this$1 = threadPoolWorker.this;
super();
}
});
ThreadPool.busy_pool_timer_set = true;
SimpleTimer.addPeriodicEvent("ThreadPool:timeout", 10000L, new TimerEventPerformer() {
final threadPoolWorker this$1;
public void perform(TimerEvent event)
{
ThreadPool.checkAllTimeouts();
}
{
this$1 = threadPoolWorker.this;
super();
}
});
}
}
}
}
if (!(runnable instanceof ThreadPoolTask))
break MISSING_BLOCK_LABEL_398;
tpt = (ThreadPoolTask)runnable;
tpt.worker = this;
task_name = tpt.getName();
if (task_name != null)
setName((new StringBuilder()).append(worker_name).append("{").append(task_name).append("}").toString());
tpt.taskStarted();
runIt(runnable);
if (task_name != null)
setName(worker_name);
if (tpt.isAutoReleaseAndAllowManual())
{
tpt.taskCompleted();
} else
{
autoRelease = false;
break; /* Loop/switch isn't completed */
}
break MISSING_BLOCK_LABEL_409;
Exception exception3;
exception3;
if (task_name != null)
setName(worker_name);
if (tpt.isAutoReleaseAndAllowManual())
{
tpt.taskCompleted();
} else
{
autoRelease = false;
break; /* Loop/switch isn't completed */
}
throw exception3;
runIt(runnable);
continue; /* Loop/switch isn't completed */
Throwable e;
e;
DebugLight.printStackTrace(e);
continue; /* Loop/switch isn't completed */
if (autoRelease)
synchronized (ThreadPool.this)
{
long elapsed = SystemTime.getCurrentTime() - run_start_time;
if (elapsed <= 10000L);
busy.remove(this);
if (busy.size() == 0 && !ThreadPool.debug_thread_pool)
synchronized (ThreadPool.busy_pools)
{
ThreadPool.busy_pools.remove(ThreadPool.this);
}
}
JVM INSTR ret 8;
if (runnable != null) goto _L2; else goto _L1
_L1:
if (autoRelease)
thread_sem.release();
ThreadPool.tls.set(null);
break MISSING_BLOCK_LABEL_638;
e;
DebugLight.printStackTrace(e);
if (autoRelease)
thread_sem.release();
ThreadPool.tls.set(null);
break MISSING_BLOCK_LABEL_638;
Exception exception7;
exception7;
if (autoRelease)
thread_sem.release();
ThreadPool.tls.set(null);
throw exception7;
}
public void setState(String _state)
{
state = _state;
}
public String getState()
{
return state;
}
protected String getWorkerName()
{
return worker_name;
}
protected ThreadPool getOwner()
{
return ThreadPool.this;
}
protected AERunnable getRunnable()
{
return runnable;
}
protected threadPoolWorker()
{
this$0 = ThreadPool.this;
super((new StringBuilder()).append(name).append("[").append(thread_name_index++).append("]").toString(), true);
state = "<none>";
setPriority(thread_priority);
worker_name = (new StringBuilder()).append(name).append("[").append(thread_name_index++).append("]").toString();
start();
}
}
private static final boolean LOG_WARNINGS = false;
private static final int WARN_TIME = 10000;
private static List busy_pools = new ArrayList();
private static boolean busy_pool_timer_set = false;
private static boolean debug_thread_pool;
private static boolean debug_thread_pool_log_on;
private static ThreadLocal tls = new ThreadLocal() {
public Object initialValue()
{
return null;
}
};
private String name;
private int max_size;
private int thread_name_index;
private long execution_limit;
private List busy;
private boolean queue_when_full;
private List task_queue;
AESemaphore thread_sem;
private int thread_priority;
private boolean warn_when_full;
private long task_total;
private long task_total_last;
private Average task_average;
private boolean log_cpu;
protected static void checkAllTimeouts()
{
List pools;
synchronized (busy_pools)
{
pools = new ArrayList(busy_pools);
}
for (int i = 0; i < pools.size(); i++)
((ThreadPool)pools.get(i)).checkTimeouts();
}
public ThreadPool(String _name, int _max_size)
{
this(_name, _max_size, false);
}
public ThreadPool(String _name, int _max_size, boolean _queue_when_full)
{
thread_name_index = 1;
task_queue = new ArrayList();
thread_priority = 5;
task_average = Average.getInstance(10000, 120);
log_cpu = false;
name = _name;
max_size = _max_size;
queue_when_full = _queue_when_full;
thread_sem = new AESemaphore((new StringBuilder()).append("ThreadPool::").append(name).toString(), _max_size);
busy = new ArrayList(_max_size);
}
private void generateEvidence(IndentWriter writer)
{
writer.println((new StringBuilder()).append(name).append(": max=").append(max_size).append(",qwf=").append(queue_when_full).append(",queue=").append(task_queue.size()).append(",busy=").append(busy.size()).append(",total=").append(task_total).append(":").append(DisplayFormatters.formatDecimal(task_average.getDoubleAverage(), 2)).append("/sec").toString());
}
public void setWarnWhenFull()
{
warn_when_full = true;
}
public void setLogCPU()
{
log_cpu = true;
}
public int getMaxThreads()
{
return max_size;
}
public void setThreadPriority(int _priority)
{
thread_priority = _priority;
}
public void setExecutionLimit(long millis)
{
execution_limit = millis;
}
public threadPoolWorker run(AERunnable runnable)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -