KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xml > internal > utils > ThreadControllerWrapper


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy 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,
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.3 2004/02/17 04:21:14 minchau Exp $
18  */

19 package com.sun.org.apache.xml.internal.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   
28   /** The ThreadController pool */
29   static ThreadController m_tpool = new ThreadController();
30
31   /**
32    * Change the ThreadController that will be used to
33    * manage the transform threads.
34    *
35    * @param tp A ThreadController object
36    */

37   public static void setThreadController(ThreadController tpool)
38   {
39     m_tpool = tpool;
40   }
41   
42   public static Thread JavaDoc runThread(Runnable JavaDoc runnable, int priority)
43   {
44     return m_tpool.run(runnable, priority);
45   }
46   
47   public static void waitThread(Thread JavaDoc worker, Runnable JavaDoc task)
48     throws InterruptedException JavaDoc
49   {
50     m_tpool.waitThread(worker, task);
51   }
52   
53   /**
54    * Thread controller utility class for incremental SAX source. Must
55    * be overriden with a derived class to support thread pooling.
56    *
57    * All thread-related stuff is in this class.
58    */

59   public static class ThreadController
60   {
61
62     /**
63      * Will get a thread from the pool, execute the task
64      * and return the thread to the pool.
65      *
66      * The return value is used only to wait for completion
67      *
68      *
69      * NEEDSDOC @param task
70      * @param priority if >0 the task will run with the given priority
71      * ( doesn't seem to be used in xalan, since it's allways the default )
72      * @returns The thread that is running the task, can be used
73      * to wait for completion
74      *
75      * NEEDSDOC ($objectName$) @return
76      */

77     public Thread JavaDoc run(Runnable JavaDoc task, int priority)
78     {
79
80       Thread JavaDoc t = new Thread JavaDoc(task);
81
82       t.start();
83
84       // if( priority > 0 )
85
// t.setPriority( priority );
86
return t;
87     }
88
89     /**
90      * Wait until the task is completed on the worker
91      * thread.
92      *
93      * NEEDSDOC @param worker
94      * NEEDSDOC @param task
95      *
96      * @throws InterruptedException
97      */

98     public void waitThread(Thread JavaDoc worker, Runnable JavaDoc task)
99             throws InterruptedException JavaDoc
100     {
101
102       // This should wait until the transformThread is considered not alive.
103
worker.join();
104     }
105   }
106  
107 }
108
Popular Tags