View Javadoc

1   /**********************************************************************
2    * ThreadService.java
3    * created on 10.08.2006 by netseeker
4    * $Id: ThreadService.java,v 1.2 2006/11/05 16:34:39 netseeker Exp $
5    * $Log: ThreadService.java,v $
6    * Revision 1.2  2006/11/05 16:34:39  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  /***
38   * A ThreadService is a wrapper around an implementation of a ThreadPool. It's just a unique, abstract interface for
39   * controlling all kinds of possible ThreadPools, which can be used by EJOE.
40   * 
41   * @author netseeker
42   * @since 0.3.9.1
43   */
44  public interface ThreadService
45  {
46  
47      /***
48       * Queues a new task for asynchronous execution in the underlying ThreadPool
49       * 
50       * @param task a task to execute within one of the available worker threads
51       */
52      public void invokeLater( Runnable task );
53  
54      /***
55       * Shutdown the underlying ThreadPool
56       */
57      public void stop();
58  
59      /***
60       * Returns the amount of worker threads which are active. Hereby "active" means the worker is currently executing a
61       * task.
62       * 
63       * @return the amount of currently active workers in the underlying ThreadPool
64       */
65      public int getActiveWorkerCount();
66  
67      /***
68       * Returns the amount of workers which are really usable in the underlying ThreadPool. The amount can differ from
69       * {@link #getExpectedPoolsize()} caused by crashed (or due to too less memory unstarted) worker threads.
70       * 
71       * @return the amount of really usable worker threads in the underlying ThreadPool
72       */
73      public int getCurrentPoolsize();
74  
75      /***
76       * Returns the amount of workers the ThreadService expects to to have in the underlying ThreadPool according to the
77       * currently active pool size.
78       * 
79       * @return the amount of workers which should be started in the underlying ThreadPool
80       */
81      public int getExpectedPoolsize();
82  
83      /***
84       * Resizes the amount of worker threads in the ThreadService to the given size.
85       * 
86       * @param poolSize the new amount of worker threads in the ThreadService
87       */
88      public void resize( int poolSize );
89  }