Example of Using JavaCGIBridgePool

Demonstration

This example demonstrates the use of a JavaCGIBridgePool to manage objects. The Pool is extremely useful when you are doing many asynchronous calls using callOneWay and you want another class to manage whether or not the particular JavaCGIBridge objects that have been previously deployed are still busy processing.

The pool only hands back objects that are no longer busy or creates new ones if all of the current JavaCGIBridge objects it holds are busy. If there are as many busy objects as maxObjects, then the pool will wait until one is freed up instead of creating a new one.

This applet allows you to enter the max objects to allow the pool to handle. The default is two. This is signicant because when the "Call CGI" button is pressed, the pool will immediately be called upon to give out 5 objects and call them asynchrnously in a row. Furthermore, each object will be passed a URL with a different timeout. The first timeout.cgi will be called with a sleep time of 1 second, the second will be called with a sleep time of 2 seconds, the third has 3 seconds, etc.

Finally, the applet will return the amount of time it took to process the request. You will notice that if you pop in a high number like 6 or 10 for maxObjects (or 0 for no max objects) then the applet will return very quickly. This is because all 5 objects will be created easily and quickly by the pool.

However, if you use a lower number like 1 or 2, it will take a long time to return because the previous objects need to return before the pool can give them back out. Notice that the lower the number, the longer it takes to return.

Let's look at the case for maxObjects == 1. In this case, the first timeout.cgi is called with a delay of 1 second. Then, the pool is asked immediately for another object. Unfortunately, it has to wait til the first one completes (1 second). Finally, the pool grants the second timeout.cgi (which runs for 2 seconds). But the third request has to wait for the second timeout.cgi (2 seconds). If you do the math with steadily increasing timeout values (1+2+3+4) equals about 10 seconds of delay before returning.

The milliseconds of delay are printed in the TextArea block. Generally, they will be a bit higher than you expect because of the overhead in method calls and calling and returning from JavaCGIBridgePool and the JavaCGIBridge objects.

Applet Demonstrating JavaCGIBridgePool Usage

View The Source To Example10Applet.java

View The Source To JavaCGI Bridge.java

View The JavaCGIBridge JavaDoc File

View The Source To JavaCGIBridgePool.java

View The JavaCGIBridgePool JavaDoc File

View The Source To JavaCGIBridgeTimeOutException.java

View The JavaCGIBridgeTimeOutException JavaDoc File

View The Source To timeout.cgi

Plain CGI script which sleeps for {timeout} seconds.

Run timeout.cgi CGI/Perl Script

Run timeout.cgi CGI/Perl Script with 1 second delay

Run timeout.cgi CGI/Perl Script with 2 second delay

Gunther Birznieks <gunther@clark.net>