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