KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > util > ThreadPools


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10 package org.mmbase.util;
11 import edu.emory.mathcs.backport.java.util.concurrent.*;
12 import org.mmbase.util.logging.*;
13 /**
14  * Generic MMBase Thread Pools
15  *
16  * @since MMBase 1.8
17  * @author Michiel Meewissen
18  * @version $Id: ThreadPools.java,v 1.5 2006/06/20 20:18:45 michiel Exp $
19  */

20 public abstract class ThreadPools {
21     private static final Logger log = Logging.getLoggerInstance(ThreadPools.class);
22
23     /**
24      * Generic Thread Pools which can be used by 'filters'.
25      */

26     public static final Executor filterExecutor = Executors.newCachedThreadPool();
27
28
29     /**
30      * For jobs there are 'scheduled', and typically happen on larger time-scales.
31      */

32     public static final Executor jobsExecutor = new ThreadPoolExecutor(2, 10, 5, TimeUnit.MINUTES, new LinkedBlockingQueue(), new ThreadFactory() {
33
34             public Thread JavaDoc newThread(Runnable JavaDoc r) {
35                 Thread JavaDoc t = new Thread JavaDoc(r, "JOBTHREAD") {
36                         /**
37                          * Overrides run of Thread to catch and log all exceptions. Otherwise they go through to app-server.
38                          */

39                         public void run() {
40                             try {
41                                 super.run();
42                             } catch (Throwable JavaDoc t) {
43                                 log.error("Error during job: " + t.getClass().getName() + " " + t.getMessage(), t);
44                             }
45                         }
46                     };
47                 t.setDaemon(true);
48                 return t;
49             }
50         });
51
52
53 }
54
Popular Tags