1 23 24 package com.sun.enterprise.web.connector.grizzly; 25 26 import java.util.concurrent.ThreadFactory ; 27 28 34 public class GrizzlyThreadFactory implements ThreadFactory { 35 36 39 protected String name; 40 41 44 protected int port; 45 46 49 protected int threadCount; 50 51 52 55 protected int priority; 56 57 58 61 private final static ThreadGroup threadGroup = new ThreadGroup ("Grizzly"); 62 63 69 public GrizzlyThreadFactory(String name, int port,int priority){ 70 this.name = name; 71 this.port = port; 72 this.priority = priority; 73 } 74 75 76 81 public Thread newThread(Runnable r){ 82 Thread t = new Thread (threadGroup,r); 83 t.setName(name + "WorkerThread-" + port + "-" + threadCount); 84 t.setPriority(priority); 85 t.setDaemon(true); 86 87 threadCount++; 88 return t; 89 } 90 91 92 95 public ThreadGroup getThreadGroup(){ 96 return threadGroup; 97 } 98 99 100 103 public boolean interruptThread(long threadID){ 104 Thread [] threads = new Thread [threadGroup.activeCount()]; 105 threadGroup.enumerate(threads); 106 107 for (Thread thread: threads){ 108 if ( thread != null && thread.getId() == threadID ){ 109 if ( Thread.State.RUNNABLE != thread.getState()){ 110 try{ 111 thread.interrupt(); 112 return true; 113 } catch (Throwable t){ 114 ; } 116 } 117 } 118 } 119 return false; 120 } 121 } 122 | Popular Tags |