Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.sonatype.sisu.jetty.thread;
  
  
An extension of Jetty's default org.eclipse.jetty.util.thread.QueuedThreadPool, that makes possible to plug-in custom java.util.concurrent.ThreadFactory that suits your needs (ie. to instrument or do anything else with the Threads being created for Jetty's pool). Only one method is overridden, the newThread(java.lang.Runnable), and all the constructors are kept too. Also, JettyWatchdog daemon thread is started to nag if any "thread death" is detected.

To use this class in Server, you need following line(s) in your jetty.xml:

 <Configure id="Server" class="org.eclipse.jetty.server.Server">
   <Set name="threadPool">
     <New class="org.sonatype.sisu.jetty.thread.InstrumentedQueuedThreadPool"/>
   </Set>
   <Call name="addConnector">
   ...
 
By default (if configured exactly as above), ThreadFactoryImpl will be used, and daemon thread running JettyWatchdog will be started. The result is that Jetty's QTP threads will get their own thread group, all of them will have LoggingUncaughtExceptionHandler installed, and system will nag you with WARN level logs periodically (every 10 seconds) from the moment that "unexpected death(s)" of QTP threads are detected.

Author(s):
cstamas
Since:
1.3
 
     extends QueuedThreadPool
 {
     private final ThreadFactory threadFactory;
 
     public InstrumentedQueuedThreadPool()
     {
         thisnew ThreadFactoryImpl() );
     }
 
     public InstrumentedQueuedThreadPoolfinal BlockingQueue<RunnablejobQ )
     {
         thisnew ThreadFactoryImpl(), jobQ );
     }
 
     public InstrumentedQueuedThreadPoolfinal int maxThreads )
     {
         thisnew ThreadFactoryImpl(), maxThreads );
     }
 
     public InstrumentedQueuedThreadPoolfinal ThreadFactory threadFactory )
     {
         super();
         this. = validatethreadFactory );
         startWatchdog();
     }
 
     public InstrumentedQueuedThreadPoolfinal ThreadFactory threadFactoryfinal BlockingQueue<RunnablejobQ )
     {
         superjobQ );
         this. = validatethreadFactory );
         startWatchdog();
     }
 
     public InstrumentedQueuedThreadPoolfinal ThreadFactory threadFactoryfinal int maxThreads )
     {
         supermaxThreads );
         this. = validatethreadFactory );
         startWatchdog();
     }
 
     public ThreadFactory getThreadFactory()
     {
         return ;
     }
 
     protected ThreadFactory validatefinal ThreadFactory threadFactory )
     {
         if ( threadFactory == null )
         {
             throw new NullPointerException"ThreadFactory set on thread pool cannot be null!" );
         }
         return threadFactory;
     }
 
     protected void startWatchdog()
     {
         final Thread watchdogThread = new Threadnew JettyWatchdog(), "JettyQTPWatchdog" );
         watchdogThread.setDaemontrue );
         watchdogThread.setPriority. );
         watchdogThread.start();
     }
 
     @Override
     protected Thread newThreadfinal Runnable runnable )
     {
         return .newThreadnew RunnableWrapperrunnable ) );
    }
New to GrepCode? Check out our FAQ X