FileDocCategorySizeDatePackage
WorkerThreadImpl.javaAPI DocGlassfish v2 API4747Fri May 04 22:37:06 BST 2007com.sun.enterprise.web.connector.grizzly

WorkerThreadImpl

public class WorkerThreadImpl extends Thread implements WorkerThread
Simple worker thread used for processing HTTP requests. All threads are synchronized using a Pipeline object
author
Jean-Francois Arcand

Fields Summary
protected Runnable
target
What will be run.
protected ByteBuffer
byteBuffer
The ByteBuffer used when Task are executed.
protected Pipeline
pipeline
The Pipeline on which this thread synchronize.
protected volatile boolean
doTask
Looing variable.
protected static final ThreadGroup
threadGroup
The ThreadGroup used.
Constructors Summary
public WorkerThreadImpl(ThreadGroup threadGroup, Runnable runnable)
Create a Thread that will synchronizes/block on Pipeline instance.

    
                    
        
        super(threadGroup, runnable);                    
        setDaemon(true);
        target = runnable;
    
public WorkerThreadImpl(Pipeline pipeline, String name)
Create a Thread that will synchronizes/block on Pipeline instance.

        super(threadGroup, name);                    
        this.pipeline = pipeline;
        setDaemon(true);        
    
Methods Summary
public java.nio.ByteBuffergetByteBuffer()
Return the ByteBuffer shared this thread

        return byteBuffer;
    
public voidrun()
Execute a Task.


        if ( target != null ){
            target.run();
            return;
        }
        
        while (doTask) {
            try{
                // Wait for a Task to be added to the pipeline.
                Task t = pipeline.getTask();
                if ( t != null){
                    t.run();                
                    t = null;
                }
            } catch (Throwable t) {
                if ( byteBuffer != null){
                    byteBuffer.clear();
                }
                SelectorThread.logger().log(Level.FINE,
                        "workerThread.httpException",t);
            }
        }
    
public voidsetByteBuffer(java.nio.ByteBuffer byteBuffer)
Set the ByteBuffer shared this thread

        this.byteBuffer = byteBuffer;
    
public voidterminate()
Stop this thread. If this Thread is performing atask, the task will be completed.

        doTask = false;