Applet Producer-Consumer

Imagined Cities
Tracerote Protocols: ICMP, IP, UDP Traceroute Servlet
Traceroute List
Traceroute Download
WhoIs Service
URL Geography
From PSH to ACK

Your Browser hasn't Java support.
Get a new Browser or enable Java!

Imagined Cities

Home at LK.NET. Where cultures of the world converge.

Open Directory Project at

Java FAQ

  It can be chosen from
1 to 4 Consumers
simultaneously running
in the PC Console and
monitoring in the TM View. Producer and every
Consumer can be started
and stopped from the
Applet panel.
  1st Consumer looks over Notifications received
from the Producer and
lets go about for 20%
of them. 2d Consumer
lets through about 33%.
3d Consumer lets go
about 50% and 4th
accepts all 100%.
Production period default
value is set to 300 ms
and it can be changed
from 200 ms to 1900 ms.
The more production
period is set the less
queue size, which can be batched and passed to a
  In every loop of getting
Notifications from the
Queue each Consumer
waits for batch size to be
collected in the Queue or
for timeout expiring.
Consumer timeout is set
to the 7000 ms and the
batch size is set to the 20.   Consumer behavior can
be modified: wait for full
batch (20 Notifications),
for 50% (10 Notifications),
for 25% (5 Notifications).



Online Graphics Generator

    gives solution to the asynchronous production and consumption of information. Producer place Objects in the Queue and Consumer pulls them from the Queue. In the distributed system the Producer (sender of data) and Consumer(receiver of data) may reside in different sub-systems, which may be integrated not so tightly.
     For the model with simple direct topology Consumer is the direct listener of Producer. For the model with Queuing adapter sending of an event in Producer is decoupled with receiving of events in the Consumer by Queue. Other models are considered in the
Event Model .
     The Asynchronous and Synchronous layers in the Architectural Pattern Half-Sync/Half-Async  communicate as a Producer (Asynchronous layer) and Consumer (Synchronous layer) by passing messages through Message Queue.
     Message-Driven Beans of the EJB 2.0 allow a loose coupling between the Message Producer and the Message Consumer. Application example of this framework is the Publish/Subscribe Application , where Producer is a Publisher and Consumer is a Subscriber.
     The typical Producer/Consumer example can be found on the Java Sun site.
     Java Message Service (JMS) programming model includes a supplier named MessageProducer and consumer named MessageConsumer. This model is very close to the Notification Service model. In the article JMS and CORBA Notification Interworking relation between Notification Service and JMS interfaces is considered

    Animation implemented in two Views: Producer Consumer Console (PC Console) and Thread Monitor (TM View), every view in own thread, updating with own renewal period: 200 ms for PC Console and 400 ms for TM View.

     public class PCCanvas extends Canvas implements Runnable {
        public synchronized void setPCCanvasStop() { runPCCanvas = false; }
        public synchronized void setPCCanvasRun() { runPCCanvas = true; }
        public synchronized boolean getPCCanvasFlag() { return runPCCanvas; }
        public void run() {
          while(getPCCanvasFlag()) {
            try {
            } catch ( java.lang.InterruptedException ie) {
        public void startPCCanvas() {
	  if (threadPCCanvas == null)
		  threadPCCanvas = new Thread(this, "PC Console");

    When browser leaves current page the method setPCCanvasStop() of class PCCanvas is invoked from the method stop() of class ApprocoApplet, inheriting from the Applet and repaint loop will be broken. Similarly, for the TM View:

     public class TMCanvas extends Canvas implements Runnable {         
       public void run() {
          while(getTMCanvasFlag()) {
            try {
            } catch ( java.lang.InterruptedException ie) {

    There are 7 threads in the applet Approco: 4 Consumers Threads, Producer Thread, PC Console Thread and TM View Thread. 6 of these threads are monitored in the TM View (all except for TM View itself). As it was menthioned above polling period for thread List is set to the 400 ms. But these threads not all thread running in the applet. Open "Java Console" of your browser and type "t" (threads). Java Console shows AWT threads AWT-EventQueue-0 and AWT-Windows. Some other threads of Java VM of concrete browser are running with the applet.
AWT-EventQueue-0 thread calls object's event handling methods such as actionPerformed .

  public class ConsumerButton extends Button implements ActionListener {     
     public ConsumerButton(String str,int numb) {
        numbOfButton = numb;
        name = str;
     public void actionPerformed(java.awt.event.ActionEvent ae) {
        String name = ae.getActionCommand();

        if (isCurrentNameEqualStop()) {
        if (isCurrentNameEqualStart()) {

      Snapshot from the
  Internet Explorer 5 Java Console
Pri 5 AWT-EventQueue-0 Pri 5 AWT-Windows Pri 10 TaskManager notify thread Pri 5 main Pri 6 thread applet-Approco/ApprocoApplet.class Pri 6 Consumer 1 Pri 6 Consumer 2 Pri 6 Consumer 3 Pri 6 Consumer 4 Pri 6 Producer Pri 6 Monitor Pri 6 PC Console Pri 5 Global Task Manager Thread #0 Pri 5 Global Task Manager Thread #1
     Snapshot from the
 Netscape 6 Java Console
main,5,alive AWT-Windows,6,alive,dameon AWT-Shutdown,6,alive AWT-EventQueue-0,6,alive TimerQueue,5,alive,dameon Thread-2,5,alive Thread-3,5,alive thread applet-Approco/ApprocoApplet.class,4,alive AWT-EventQueue-1,4,alive Consumer 1,4,alive Consumer 2,4,alive Consumer 3,4,alive Consumer 4,4,alive Producer,4,alive Monitor,4,alive PC Console,4,alive

    The applet's update and paint methods do the actual drawing and execute in the AWT-EventQueue-0 thread because updating and painting are panel events. How to get Java Trace Stack for Solaris and Windows platform described in the An Introduction to Java Stack Traces or in Advanced Programming for the JavaTM 2 Platform

    simplifiers design and writing code. Some advantages of MVC are clarified in the
the model-view-controller (MVC) design pattern. Just by breaking the program down into the three MVC components, gains many .... Multiply view: the application can display the state of model in some views. Applet Approco has two views: Thread Monitor View and Producer Consumer Console. Applet controller contains some listeners: "Number of Consumers", "Queue Mode", "Production Period", "URL Label". Cristobal Baray   prefers pure MVC pattern, where controller doesn't control view , only through model. It maybe approach, where controller controls both model and view, and model also updates view.

1. Software Engineering - Fall 1999, by Michael Elhadad

2. Patterns for Concurrent, Parallel, and Distributed Systems, by Douglas C. Schmidt, November 2001
Event Patterns. Concurrency Patterns and Idioms. Initialization Patterns. Miscellaneous Patterns

3. Migrating from Enterprise JavaBeansTM(EJBTM) 1.1 to 2.0, By Beth Stearns, September 2001
Using the Query Language. Using Local Interfaces. Design Implications. Using 2.0 Container-Managed Persistence. Implementing 2.0 CMP. Defining Persistent Fields. Defining Entity Bean Relationships. Using Message-Driven Beans.

4. EJB 2 Message-Driven Beans, by Dion Almaer
Working with the new Message Driven Beans and JMS. JMS Architecture. Point-to-Point application. Publish/Subscribe Application

5. The Producer/Consumer example
Essential Java Classes. Threads: Doing Two or More Tasks At Once

6. Java Message Service, Notification Service - WhitePaper, OpenFusion, May 2001
The Notification Service supports a comprehensive QoS framework. NS supports guaranteed delivery, supports priority event ordering.

7. JMS and CORBA Notification Interworking, by Steve Trythall, 12/12/2001
CORBA Notification Service, JMS, Integration Points. Message Conversions. Message Types. Message Filtering.

8. Creating a Threaded Slide Show Applet, By Monica Pawlan, March 16, 2001
Running the Slide Show Applet. How the Threaded Applet Works. Threaded Applet Anatomy. Initializing, Starting, Pausing, Stopping, Exiting the Applet. Running The Timer Thread. Object-Level Locks. Updating and Painting the Display. AWT-EventQueue-0 thread.

9. An Introduction to Java Stack Traces, by Calvin Austin, July 1998
How are Java Stack Traces Generated? Sending a signal to the Java Virtual Machine. The Java Virtual Machine generates a stack trace for you. Using debugging tools or Java API calls. Finding the current thread. Runnable threads. Determining the Thread States. Examining Monitors.

10. Advanced Programming for the JavaTM 2 Platform
Sending a signal to the Java VM. Using Debugging Tools or API Calls.

11. The model-view-controller (MVC) design pattern, by Cristobal Baray
MVC introduction. MVC advantages. MVC toy example. The heartbeat model. The heartbeat controller. The heartbeat view. MVC things to do... MVC pointers.

12. Model-View-Controller Pattern
How It Works. A Concrete Example. Multiple Controllers.

This applet implemented and
maintained by Rafael Stekolshchik