Methods Summary |
---|
protected static void | checkAllTimeouts()
List pools;
// copy the busy pools to avoid potential deadlock due to synchronization
// nestings
synchronized( busy_pools ){
pools = new ArrayList( busy_pools );
}
for (int i=0;i<pools.size();i++){
((ThreadPool)pools.get(i)).checkTimeouts();
}
|
protected void | checkTimeouts()
synchronized( ThreadPool.this ){
long diff = task_total - task_total_last;
task_average.addValue( diff );
task_total_last = task_total;
if ( debug_thread_pool_log_on ){
System.out.println( "ThreadPool '" + getName() + "'/" + thread_name_index + ": max=" + max_size + ",sem=[" + thread_sem.getString() + "],pool=" + thread_pool.size() + ",busy=" + busy.size() + ",queue=" + task_queue.size());
}
long now = SystemTime.getCurrentTime();
for (int i=0;i<busy.size();i++){
threadPoolWorker x = (threadPoolWorker)busy.get(i);
long elapsed = now - x.run_start_time ;
if ( elapsed > ( WARN_TIME * (x.warn_count+1))){
x.warn_count++;
if ( LOG_WARNINGS ){
DebugLight.out( x.getWorkerName() + ": running, elapsed = " + elapsed + ", state = " + x.state );
}
if ( execution_limit > 0 && elapsed > execution_limit ){
if ( LOG_WARNINGS ){
DebugLight.out( x.getWorkerName() + ": interrupting" );
}
AERunnable r = x.runnable;
try{
if ( r instanceof ThreadPoolTask ){
((ThreadPoolTask)r).interruptTask();
}else{
x.worker_thread.interrupt();
}
}catch( Throwable e ){
DebugLight.printStackTrace( e );
}
}
}
}
}
|
protected void | checkWarning()
if ( warn_when_full ){
Debug.out( "Thread pool '" + getName() + "' is full" );
warn_when_full = false;
}
|
private void | generateEvidence(IndentWriter writer)
writer.println( name + ": max=" + max_size +",qwf=" + queue_when_full + ",queue=" + task_queue.size() + ",busy=" + busy.size() + ",pool=" + thread_pool.size() + ",total=" + task_total + ":" + DisplayFormatters.formatDecimal(task_average.getDoubleAverage(),2) + "/sec");
|
public int | getMaxThreads()
return( max_size );
|
public java.lang.String | getName()
return( name );
|
public int | getQueueSize()
synchronized( this ){
return( task_queue.size());
}
|
public AERunnable[] | getQueuedTasks()
synchronized( this ){
AERunnable[] res = new AERunnable[task_queue.size()];
task_queue.toArray(res);
return( res );
}
|
public AERunnable[] | getRunningTasks()
List runnables = new ArrayList();
synchronized( this ){
Iterator it = busy.iterator();
while( it.hasNext()){
threadPoolWorker worker = (threadPoolWorker)it.next();
AERunnable runnable = worker.getRunnable();
if ( runnable != null ){
runnables.add( runnable );
}
}
}
AERunnable[] res = new AERunnable[runnables.size()];
runnables.toArray(res);
return( res );
|
public boolean | isQueued(AERunnable task)
synchronized( this ){
return( task_queue.contains( task ));
}
|
public org.gudy.azureus2.core3.util.ThreadPool$threadPoolWorker | run(AERunnable runnable, boolean high_priority)
// System.out.println( "Thread pool:" + name + " - sem = " + thread_sem.getValue() + ", queue = " + task_queue.size());
// not queueing, grab synchronous sem here
if ( !queue_when_full ){
if ( !thread_sem.reserveIfAvailable()){
// defend against recursive entry when in queuing mode (yes, it happens)
threadPoolWorker recursive_worker = (threadPoolWorker)tls.get();
if ( recursive_worker == null || recursive_worker.getOwner() != this ){
// do a blocking reserve here, not recursive
checkWarning();
thread_sem.reserve();
}else{
// run immediately
if ( runnable instanceof ThreadPoolTask ){
ThreadPoolTask task = (ThreadPoolTask)runnable;
task.worker = recursive_worker;
try{
task.taskStarted();
task.run();
}finally{
task.taskCompleted();
}
}else{
runnable.runSupport();
}
return( recursive_worker );
}
}
}
threadPoolWorker allocated_worker;
synchronized( this ){
// reserve if available is non-blocking
if ( queue_when_full && !thread_sem.reserveIfAvailable()){
allocated_worker = null;
checkWarning();
if ( high_priority ){
task_queue.add( 0, runnable );
}else{
task_queue.add( runnable );
}
}else{
if ( thread_pool.isEmpty()){
allocated_worker = new threadPoolWorker();
}else{
allocated_worker = (threadPoolWorker)thread_pool.pop();
}
if ( runnable instanceof ThreadPoolTask ){
((ThreadPoolTask)runnable).worker = allocated_worker;
}
allocated_worker.run( runnable );
}
}
return( queue_when_full?null:allocated_worker );
|
public org.gudy.azureus2.core3.util.ThreadPool$threadPoolWorker | run(AERunnable runnable)
return( run( runnable, false ));
|
public void | setExecutionLimit(long millis)
execution_limit = millis;
|
public void | setThreadPriority(int _priority)
thread_priority = _priority;
|
public void | setWarnWhenFull()
warn_when_full = true;
|