// @topic T11800 Multithreading -- Order Queue demo
// @brief class OrderQueueApp -- main class

package pckg;

public class OrderQueueApp
{
    public static void main(String[] args)
    {
        final int TAKER_COUNT = 3;   // OrderTaker threads
        final int ORDER_COUNT = 3;   // orders per 
                                     // OrderTaker thread
        final int HANDLER_COUNT = 2; // OrderHandler threads

        // create the order queue
        OrderQueue queue = new OrderQueue();

        System.out.println("Starting the order queue.");

        System.out.println("Starting " + TAKER_COUNT +
            " order takers, " + "each producing " +
            ORDER_COUNT + " orders.");

        System.out.println("Starting " + HANDLER_COUNT +
            " order handlers.\n");
        String s 
          = "     OrderTaker threads            "
          + "OrderHandler threads    \n"
          + "============================ "
          + "=============================";
        System.out.println(s);

        // create the Taker threads
        for (int i = 0; i < TAKER_COUNT; i++)
        {
            OrderTaker t = new OrderTaker(
                ORDER_COUNT, queue);
            t.start();
        }

        // create the Handler threads
        for (int i = 0; i < HANDLER_COUNT; i++)
        {
            OrderHandler h = new OrderHandler(queue);
            h.start();
        }
    }
}//class OrderQueueApp

/*
Sample output:

Starting the order queue.
Starting 3 order taker threads, each producing 3 orders.
Starting 2 order handler threads.

     OrderTaker threads              OrderHandler threads
============================    =============================
Order #1 created by Thread-1
Order #2 created by Thread-2
                                Order #1 processed by Thread-3
                                Order #2 processed by Thread-4
Order #3 created by Thread-0
Order #4 created by Thread-1
Order #5 created by Thread-2
Order #6 created by Thread-0
                                Order #3 processed by Thread-3
                                Order #4 processed by Thread-4
Order #7 created by Thread-1
Order #8 created by Thread-2
Order #9 created by Thread-0
                                Order #5 processed by Thread-3
                                Order #6 processed by Thread-4
                                Order #7 processed by Thread-3
                                Order #8 processed by Thread-4
                                Order #9 processed by Thread-3
*/