public class PoolTester extends java.lang.Object
Create the pool TestAMPool. Since PoolMgr is a singleton object, use PoolMgr.getInstance to get it. Use createPool to create the pool. Notice that createPool requires the name of the pool, the name of the package that contains the Application Module, the connect string to the database, and env, the hashtable. The createPool method is overloaded; an alternative version takes an additional parameter that lets you override the default implementation of Application Module Pooling and specify your own.
Create a second pool, SecondAMPool that connects with the same environment variables, but to an Application Module in a different package.
PoolMgr.getInstance().getPool("TestAMPool") gets a handle to the pool to work with it.
Checkout three instances. Note that the classes ApplicationPoolImpl and PoolMgr contain other functions that you can use to traverse the pool content. The ampool package also contains a PoolAdministrator Web Bean that you can use to dump the contents of the pool.
Get a handle to the second pool, check out two instances, then check in one.
Use removePool to remove the Application Module Pool. This function calls remove() on all of the Application Module instances, including ones that are currently checked out and in use, and causes them to disconnect from the database and remove all of their View Objects.
The next part of the program defines a class, CustomPool, that ensures that no more than three instances are checked out of the pool at any time. In this case, the definition of the checkout method is overridden to check that no more than three instances are checked out. If more than three are checked out, an exception is thrown.
This custom pool class is then used in a program which attempts to create more than three instances. The try-catch loop is set up to start checking out instances and to catch exceptions. When an attempt is made to create the fourth instance, an exception is thrown.
|Constructor and Description|
|Modifier and Type||Method and Description|
Provides a main for the PoolTester sample implementation of Application Module Pooling.
public void doTest() throws java.lang.Exception
public static void main(java.lang.String args)
args- arguments to the PoolTester sample implementation.