01: /*
02: * Copyright 1999-2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: /*
17: * $Id: ThreadControllerWrapper.java,v 1.5 2005/01/23 01:02:10 mcnamara Exp $
18: */
19: package org.apache.xml.utils;
20:
21: /**
22: * A utility class that wraps the ThreadController, which is used
23: * by IncrementalSAXSource for the incremental building of DTM.
24: */
25: public class ThreadControllerWrapper {
26:
27: /** The ThreadController pool */
28: private static ThreadController m_tpool = new ThreadController();
29:
30: public static Thread runThread(Runnable runnable, int priority) {
31: return m_tpool.run(runnable, priority);
32: }
33:
34: public static void waitThread(Thread worker, Runnable task)
35: throws InterruptedException {
36: m_tpool.waitThread(worker, task);
37: }
38:
39: /**
40: * Thread controller utility class for incremental SAX source. Must
41: * be overriden with a derived class to support thread pooling.
42: *
43: * All thread-related stuff is in this class.
44: */
45: public static class ThreadController {
46:
47: /**
48: * Will get a thread from the pool, execute the task
49: * and return the thread to the pool.
50: *
51: * The return value is used only to wait for completion
52: *
53: *
54: * NEEDSDOC @param task
55: * @param priority if >0 the task will run with the given priority
56: * ( doesn't seem to be used in xalan, since it's allways the default )
57: * @return The thread that is running the task, can be used
58: * to wait for completion
59: */
60: public Thread run(Runnable task, int priority) {
61:
62: Thread t = new Thread(task);
63:
64: t.start();
65:
66: // if( priority > 0 )
67: // t.setPriority( priority );
68: return t;
69: }
70:
71: /**
72: * Wait until the task is completed on the worker
73: * thread.
74: *
75: * NEEDSDOC @param worker
76: * NEEDSDOC @param task
77: *
78: * @throws InterruptedException
79: */
80: public void waitThread(Thread worker, Runnable task)
81: throws InterruptedException {
82:
83: // This should wait until the transformThread is considered not alive.
84: worker.join();
85: }
86: }
87:
88: }
|