⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 waiter.java

📁 A Waiter relays an order Object to a Producer, waits in an independent thread during the production,
💻 JAVA
字号:
     /*********************************************************************
     * <P>
     * A Waiter relays an order Object to a Producer, waits in an
     * independent thread during the production, and then delivers the
     * result using a Consumer callback method.
     * <P>
     * A Waiter is useful for when a Consumer must place an order with a
     * Producer in an independent thread but does not wish to pass a direct
     * reference to itself to the Producer for the callback operation.
     * This primarily has applications in dealing with untrusted code such
     * as mobile agents.
     * <P>
     * <B>References</B>
     * <P>
     * <A HREF="http://www.amazon.com/exec/obidos/ISBN=0201633612/">
     * Design Patterns:  Elements of Reusable Object-Oriented Software</A>
     * <BR>
     * 1995; Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides
     * <P>
     * @author
     *   <A HREF="http://www.alumni.caltech.edu/~croft">David W. Croft</A>
     * @version
     *   1998-04-07
     *********************************************************************/

     public class  Waiter implements Runnable {
     //////////////////////////////////////////////////////////////////////
     //////////////////////////////////////////////////////////////////////

     protected  Producer   producer;
     protected  Consumer   consumer;
     protected  Object     order;

     //////////////////////////////////////////////////////////////////////
     //////////////////////////////////////////////////////////////////////

     public static void  relay (
       Producer  producer, Consumer  consumer, Object  order )
     //////////////////////////////////////////////////////////////////////
     {
       new Thread ( new Waiter ( producer, consumer, order ) ).start ( );
     }

     public  Waiter (
       Producer  producer, Consumer  consumer, Object  order )
     //////////////////////////////////////////////////////////////////////
     {
       this.producer = producer;
       this.consumer = consumer;
       this.order    = order;
     }

     public void  run ( )
     //////////////////////////////////////////////////////////////////////
     {
       consumer.consume ( producer.produce ( order ) );
     }

     //////////////////////////////////////////////////////////////////////
     //////////////////////////////////////////////////////////////////////
     }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -