532 WebSphere Business Integrator Server Foundation V5.1 Handbook
System.out.println("doSomethingUseObjectPool average execution time = " +
(endTimeUsingObjectPool - startTimeUsingObjectPool) / repetitions);
System.out.println("Total average execution time = " + averageExecutionTime.doubleValue() /
totalNumberOfRepetitions.doubleValue());
System.out.println("Total average execution time using pool= " +
averageExecutionTimeUsingPool.doubleValue() / totalNumberOfRepetitions.doubleValue());
}
public void doSomething() {
try {
Object aL = customClass.newInstance(); //Create a new object
randomWait(1 + rand.nextInt(5)); //Wait between 1 and 6 miliseconds
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void doSomethingUseObjectPool() {
Object obj = oPool.getObject(); //Get an object from the object pool
randomWait(1 + rand.nextInt(5));//Wait between 1 and 6 miliseconds
oPool.returnObject(obj);//Return the object to the object pool
}
synchronized private void randomWait(int miliseconds) {
try {
this.wait(miliseconds);
} catch (InterruptedException e) {}
}
}
7. Save and close the file. All the errors from the Task view should disappear.
20.4 Unit test
To run the code in the WebSphere Test Environment, you need to add an Object
Pool Manager to the Server Configuration.
1. Open the Server perspective and create a new Integration Test Server. If you
need help with creating a test server, refer to , “Integration Server V5.1 test
environment setup” on page 563.
2. Open the Server Configuration by double-clicking the test server you have
created.
3. On the Object Pools tab, click the Add button under Server Settings, next to
the Object Pool Managers. Enter AObjectPoolManager in the Name field and
ObjectPoolMgr in the JNDI Name field. Click the OK button.
Chapter 20. Object pools 533
Figure 20-2 Creating an Object Pool Manager
4. Save the Server Configuration and right-click the Object Pool Server and
select the Start button.
5. Now we can create a client to run the Object Pools example.
a. Switch to the J2EE Perspective, Run
Run... from the menu.
b. Select WebSphere v5.1 Application Client and click the New button.
c. Enter Object Pool Client in the Name field.
d. Select WebSphere v5.1 EE for Server Type.
e. Select the Arguments tab and add the following parameter to the
Program arguments:
-CCverbose=true 500 java.util.ArrayList
Using these parameters, logging is turned on and 500 job threads are
going to be created that pool ArrayList Java objects.
f. Change all the
base_v51 directory names to ee_v51 under the VM
arguments; there are eight occurences.
g. Click Apply.
h. Click Run to run the application client.
6. On the Console, you will see output similar to what is shown in Example 20-3.
Example 20-3 Output from Object Pools example
IBM WebSphere Application Server, Release 5.1
J2EE Application Client Tool
Copyright IBM Corp., 1997-2003
WSCL0012I: Processing command line arguments.
WSCL0001I: Command line, property file, and system property arguments resolved to:
File to launch = C:/Documents and Settings/boardman/My
Documents/IBM/wsappdevie51/workspace/ObjectPoolEAR
534 WebSphere Business Integrator Server Foundation V5.1 Handbook
CC Property File = null
Client Jar File = ObjectPool.jar
Alternate DD = null
BootstrapHost = ka0klfc
BootstrapPort = <default>
Trace enabled = false
Tracefile = null
Init only = false
Classpath Parameter = null
Security Manager = disable
Security Manager Class = Not used. -CCsecurityManager=disable
Security Manager Policy = Not used. -CCsecurityManager=disable
Exit VM = false
Soap Connector Port = null
Application Parameters = 500 java.util.ArrayList
Provider URL = null
Dump Java Name Space = null
Admin Connector Host = null
Admin Connector Port = null
Admin Connector Type = null
Admin Connector User = null
WSCL0013I: Initializing the J2EE Application Client Environment.
...
WSCL0035I: Initialization of the J2EE Application Client Environment has completed.
WSCL0014I: Invoking the Application Client class ObjectTest
ObjectTest: looking for ObjectPoolManager
ObjectTest: starting thread: JobThread_0
ObjectTest: starting thread: JobThread_1
ObjectTest: starting thread: JobThread_2
ObjectTest: starting thread: JobThread_3
ObjectTest: starting thread: JobThread_4
ObjectTest: starting thread: JobThread_5
...
Exiting threadJobThread_128
doSomething average execution time = 63
doSomethingUseObjectPool average execution time = 23
Total average execution time = 0.06144919781625436
Total average execution time using pool= 0.10548360936703147
...
Exiting threadJobThread_419
doSomething average execution time = 11
doSomethingUseObjectPool average execution time = 5
Total average execution time = 14.616670701202292
Total average execution time using pool= 8.448640361494393

Get WebSphere Business Integration Server Foundation V5.1 Handbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.