KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > quartz > spi > ThreadPool


1 /*
2  * Copyright 2004-2005 OpenSymphony
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy
6  * of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations
14  * under the License.
15  *
16  */

17
18 /*
19  * Previously Copyright (c) 2001-2004 James House
20  */

21 package org.quartz.spi;
22
23 import org.quartz.SchedulerConfigException;
24
25 /**
26  * <p>
27  * The interface to be implemented by classes that want to provide a thread
28  * pool for the <code>{@link org.quartz.core.QuartzScheduler}</code>'s use.
29  * </p>
30  *
31  * <p>
32  * <code>ThreadPool</code> implementation instances should ideally be made
33  * for the sole use of Quartz. Most importantly, when the method
34  * <code>blockForAvailableThreads()</code> returns a value of 1 or greater,
35  * there must still be at least one available thread in the pool when the
36  * method <code>runInThread(Runnable)</code> is called a few moments (or
37  * many moments) later. If this assumption does not hold true, it may
38  * result in extra JobStore queries and updates, and if clustering features
39  * are being used, it may result in greater imballance of load.
40  * </p>
41  *
42  * @see org.quartz.core.QuartzScheduler
43  *
44  * @author James House
45  */

46 public interface ThreadPool {
47
48     /*
49      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
50      *
51      * Interface.
52      *
53      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
54      */

55
56     /**
57      * <p>
58      * Execute the given <code>{@link java.lang.Runnable}</code> in the next
59      * available <code>Thread</code>.
60      * </p>
61      *
62      * <p>
63      * The implementation of this interface should not throw exceptions unless
64      * there is a serious problem (i.e. a serious misconfiguration). If there
65      * are no immediately available threads <code>false</code> should be returned.
66      * </p>
67      *
68      * @return true, if the runnable was assigned to run on a Thread.
69      */

70     boolean runInThread(Runnable JavaDoc runnable);
71
72     /**
73      * <p>
74      * Determines the number of threads that are currently available in in
75      * the pool. Useful for determining the number of times
76      * <code>runInThread(Runnable)</code> can be called before returning
77      * false.
78      * </p>
79      *
80      * <p>The implementation of this method should block until there is at
81      * least one available thread.</p>
82      *
83      * @return the number of currently available threads
84      */

85     int blockForAvailableThreads();
86
87     /**
88      * <p>
89      * Called by the QuartzScheduler before the <code>ThreadPool</code> is
90      * used, in order to give the it a chance to initialize.
91      * </p>
92      */

93     void initialize() throws SchedulerConfigException;
94
95     /**
96      * <p>
97      * Called by the QuartzScheduler to inform the <code>ThreadPool</code>
98      * that it should free up all of it's resources because the scheduler is
99      * shutting down.
100      * </p>
101      */

102     void shutdown(boolean waitForJobsToComplete);
103
104     int getPoolSize();
105 }
106
Popular Tags