FileDocCategorySizeDatePackage
GrizzlyThreadFactory.javaAPI DocGlassfish v2 API4533Fri May 04 22:37:04 BST 2007com.sun.enterprise.web.connector.grizzly

GrizzlyThreadFactory

public class GrizzlyThreadFactory extends Object implements ThreadFactory
Customized ThreadFactory used by the Pipeline instance.
author
Jean-Francois Arcand

Fields Summary
protected String
name
The name used when creating threads
protected int
port
The port used when created threads' name.
protected int
threadCount
The number of created threads.
protected int
priority
The priority used when creating threads.
private static final ThreadGroup
threadGroup
The ThreadGroup used.
Constructors Summary
public GrizzlyThreadFactory(String name, int port, int priority)
Create an instance of ThreadFactory

param
name the name of thread who will be created by this factory
param
port the port of thread who will be created by this factory
param
priority the priority of thread who will be created by this factory

    
                                                      
         
        this.name = name;
        this.port = port;
        this.priority = priority;
    
Methods Summary
public java.lang.ThreadGroupgetThreadGroup()
Return the ThreadGroup used by this factory

        return threadGroup;
    
public booleaninterruptThread(long threadID)
Interrupt the Thread using it thread id

        Thread[] threads = new Thread[threadGroup.activeCount()];
        threadGroup.enumerate(threads);
               
        for (Thread thread: threads){
            if ( thread != null && thread.getId() == threadID ){                
                if ( Thread.State.RUNNABLE != thread.getState()){
                    try{
                        thread.interrupt();
                        return true;
                    } catch (Throwable t){
                        ; // Swallow any exceptions.
                    }
                }
            }
        }
        return false;
    
public java.lang.ThreadnewThread(java.lang.Runnable r)
Create a new thread.

param
r an instance of a Task.
return
a new Thread.

        WorkerThreadImpl t = new WorkerThreadImpl(threadGroup,r);
        t.setName(name + "WorkerThread-"  + port + "-" + threadCount);
        t.setPriority(priority);
        t.setDaemon(true);
      
        threadCount++;
        return t;