View Javadoc

1   /**********************************************************************
2    * ThreadPoolFactory.java
3    * created on 10.08.2006 by netseeker
4    * $Id: ThreadPoolFactory.java,v 1.2 2006/11/05 16:34:38 netseeker Exp $
5    * $Log: ThreadPoolFactory.java,v $
6    * Revision 1.2  2006/11/05 16:34:38  netseeker
7    * Code cleanup, added support of JDK 1.5  thread pools
8    *
9    * Revision 1.1  2006/08/10 18:36:04  netseeker
10   * added abstraction of ThreadPools and an Executor based implementation for Java >= 1.5
11   *
12   *
13   * ====================================================================
14   *
15   *  Copyright 2005-2006 netseeker aka Michael Manske
16   *
17   *  Licensed under the Apache License, Version 2.0 (the "License");
18   *  you may not use this file except in compliance with the License.
19   *  You may obtain a copy of the License at
20   *
21   *      http://www.apache.org/licenses/LICENSE-2.0
22   *
23   *  Unless required by applicable law or agreed to in writing, software
24   *  distributed under the License is distributed on an "AS IS" BASIS,
25   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26   *  See the License for the specific language governing permissions and
27   *  limitations under the License.
28   * ====================================================================
29   *
30   * This file is part of the EJOE framework.
31   * For more information on the author, please see
32   * <http://www.manskes.de/>.
33   *
34   *********************************************************************/
35  package de.netseeker.ejoe.concurrent;
36  
37  import de.netseeker.ejoe.EJConstants;
38  
39  /***
40   * A factory producing ThreadPools. The factory will produce EJOEs default ThreadPool implementation for Java < 1.5.0
41   * and a Executor-based implementation for Java >= 1.5.0.
42   * 
43   * @author netseeker
44   * @since 0.3.9.1
45   */
46  public class ThreadPoolFactory
47  {
48  
49      /***
50       * Creates a new ThreadPool with a fixed size, the worker threads in the pool will belong to the given ThreadGroup.
51       * 
52       * @param size limit of the pool
53       * @param group ThreadGroup to which the workers will belong to.
54       * @return a new fix-sized ThreadPool
55       */
56      public static ThreadService createFixedThreadPool( int size, ThreadGroup group )
57      {
58          if ( EJConstants.JAVA_VERSION_INT >= 150 )
59              return new Jdk15ThreadPool( group, size );
60          else
61              return new ThreadPool( group, size );
62      }
63  
64      /***
65       * Creates a new ThreadPool with a fixed size, the worker threads in the pool will belong to the ThreadGroup of the
66       * caller.
67       * 
68       * @param size size limit of the pool
69       * @return
70       */
71      public static ThreadService createFixedThreadPool( int size )
72      {
73          if ( EJConstants.JAVA_VERSION_INT >= 150 )
74              return new Jdk15ThreadPool( size );
75          else
76              return new ThreadPool( size );
77      }
78  }