FileDocCategorySizeDatePackage
StandardThreadExecutor.javaAPI DocApache Tomcat 6.0.148680Fri Jul 20 04:20:30 BST 2007org.apache.catalina.core

StandardThreadExecutor

public class StandardThreadExecutor extends Object implements org.apache.catalina.Executor

Fields Summary
protected int
threadPriority
protected boolean
daemon
protected String
namePrefix
protected int
maxThreads
protected int
minSpareThreads
protected int
maxIdleTime
protected ThreadPoolExecutor
executor
protected String
name
private org.apache.catalina.util.LifecycleSupport
lifecycle
Constructors Summary
public StandardThreadExecutor()

    // ---------------------------------------------- Constructors
      
        //empty constructor for the digester
    
Methods Summary
public voidaddLifecycleListener(org.apache.catalina.LifecycleListener listener)
Add a LifecycleEvent listener to this component.

param
listener The listener to add

        lifecycle.addLifecycleListener(listener);
    
public voidexecute(java.lang.Runnable command)

        if ( executor != null ) {
            try {
                executor.execute(command);
            } catch (RejectedExecutionException rx) {
                //there could have been contention around the queue
                if ( !( (TaskQueue) executor.getQueue()).force(command) ) throw new RejectedExecutionException();
            }
        } else throw new IllegalStateException("StandardThreadPool not started.");
    
public org.apache.catalina.LifecycleListener[]findLifecycleListeners()
Get the lifecycle listeners associated with this lifecycle. If this Lifecycle has no listeners registered, a zero-length array is returned.

        return lifecycle.findLifecycleListeners();
    
public intgetActiveCount()

        return (executor != null) ? executor.getActiveCount() : 0;
    
public longgetCompletedTaskCount()

        return (executor != null) ? executor.getCompletedTaskCount() : 0;
    
public intgetCorePoolSize()

        return (executor != null) ? executor.getCorePoolSize() : 0;
    
public intgetLargestPoolSize()

        return (executor != null) ? executor.getLargestPoolSize() : 0;
    
public intgetMaxIdleTime()

        return maxIdleTime;
    
public intgetMaxThreads()

        return maxThreads;
    
public intgetMinSpareThreads()

        return minSpareThreads;
    
public java.lang.StringgetName()

        return name;
    
public java.lang.StringgetNamePrefix()

        return namePrefix;
    
public intgetPoolSize()

        return (executor != null) ? executor.getPoolSize() : 0;
    
public intgetThreadPriority()

        return threadPriority;
    
public booleanisDaemon()


        return daemon;
    
public voidremoveLifecycleListener(org.apache.catalina.LifecycleListener listener)
Remove a LifecycleEvent listener from this component.

param
listener The listener to remove

        lifecycle.removeLifecycleListener(listener);
    
public voidsetDaemon(boolean daemon)

        this.daemon = daemon;
    
public voidsetMaxIdleTime(int maxIdleTime)

        this.maxIdleTime = maxIdleTime;
    
public voidsetMaxThreads(int maxThreads)

        this.maxThreads = maxThreads;
    
public voidsetMinSpareThreads(int minSpareThreads)

        this.minSpareThreads = minSpareThreads;
    
public voidsetName(java.lang.String name)

        this.name = name;
    
public voidsetNamePrefix(java.lang.String namePrefix)

        this.namePrefix = namePrefix;
    
public voidsetThreadPriority(int threadPriority)

        this.threadPriority = threadPriority;
    
public voidstart()

        lifecycle.fireLifecycleEvent(BEFORE_START_EVENT, null);
        TaskQueue taskqueue = new TaskQueue();
        TaskThreadFactory tf = new TaskThreadFactory(namePrefix);
        lifecycle.fireLifecycleEvent(START_EVENT, null);
        executor = new ThreadPoolExecutor(getMinSpareThreads(), getMaxThreads(), maxIdleTime, TimeUnit.MILLISECONDS,taskqueue, tf);
        taskqueue.setParent( (ThreadPoolExecutor) executor);
        lifecycle.fireLifecycleEvent(AFTER_START_EVENT, null);
    
public voidstop()

        lifecycle.fireLifecycleEvent(BEFORE_STOP_EVENT, null);
        lifecycle.fireLifecycleEvent(STOP_EVENT, null);
        if ( executor != null ) executor.shutdown();
        executor = null;
        lifecycle.fireLifecycleEvent(AFTER_STOP_EVENT, null);