CIS 35A: Introduction to Java Programming

Home | Green Sheet | Lectures | Assignments | FAQ | Grades

Threads

Threads
Application
Orderhhandler class

The code for the OrderHandler class

public class OrderHandler extends Thread
{
    private OrderQueue orderQueue;

    public OrderHandler(OrderQueue orderQueue)
    {
        this.orderQueue = orderQueue;
    }

    public void run()
    {
        Order order;
        while (true)
        {
            order = orderQueue.pullOrder();     // get next available order
            System.out.println("\t\t\t\t" + order.toString() + " processed by "
                + this.getName());
            try
            {
                Thread.sleep(2000);             // delay two seconds
            }
            catch (InterruptedException e) {}   // ignore interruptions
        }
    }
}
Previous | Order Queue application | Classes | OrderQueueApp class | Order class | OrderTaker class | Orderhhandler class | OrderQueue class