?? waiter.java
字號(hào):
/*********************************************************************
* <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 ) );
}
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -