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