FITECH Laboratories spacer
graphic Company graphic Products graphic Support graphic Customers graphic Partners
The Power of Choice
spacer » Buy graphic » Try graphic » Map graphic » Contact graphic
spacer
spacer
xTier™
Overview
xTier Services
Business Case
Documentation
F.A.Q.
Buy xTier™
Try xTier™
Professional Services
graphic
spacer xTier
spacer
objpool
Product: xTier™/LWC 2.3
Whitepaper: n/a
spacer
 support@fitechlabs.com
 Download
 Buy
 Depends: log
 Related: n/a
xTier™ Navigator:
cache cluster config email i18n
ioc info jmx jndi security
log marshal objpool os fs
tx uidgen workflow jobs
db startup jms grid

Description
The 'objpool' service provides general purpose object pooling facility. Main features of the object pool service include but not limited to:

  • Ability to pool plain Java objects (POJOs).
  • Having flexiable growth policies.
  • Statistical information for object and thread pools.
  • Ability to programatically control pool's size.
  • Notification and invalidation capabilities for pool objects.
  • Thread pool that is specifically designed to work with threads.
  • Pre-built pool objects and factories for primitive type arrays.
  • Unified XML-based configuration.

 Top

Configuration
'objpool' service acts as a factory for the object pools and as a container. Once object pool is created, it is stored in the service and can later be retrived by name or deleted. Object pool can be created at runtime or specified in XML configuration. Object pools specified in configuration are created automatically and can be access at runtime by their names.

'objpool' service is configured via pre-defined xtier_objpool.xml configuration file. This file follows standard xTier™ service configuration pattern that can be demonstrated by the following complete example of object pool configuration:

1<xtier-objpool>
2  <region name="examples">
3    <!-- Test pool. -->
4        <pool name="my.pool.xml" size="5" lazy="true">
5            <factory>
6                <ioc policy="new">
7                    <java class="com.fitechlabs.xtier.examples.
8                        services.objpool.FooBarFactory"/>
9                </ioc>
10            </factory>
11            
12            <resize-policy>
13                <ioc policy="new">
14                    <java class="com.fitechlabs.xtier.services.
15                        objpool.policies.ObjectPoolGrowPolicy">
16                        <ctor>
17                            <!-- 
18                                Double the size whenever pool is 
19                                empty. Pool will grow by 
20                                'pool.getSize() * 1'.
21                            -->
22                            <arg type="float32">1</arg> 
23                        </ctor>
24                    </java>
25                </ioc>
26            </resize-policy>
27        </pool>
28  </region>
29</xtier-objpool>

'objpool' configuration region consists of zero or more <pool> tags each defining an object pool. Each <pool> tag contains mandatory <factory> IoC-based tag that defines object pool factory to be used with this object pool.

Each <pool> and <thread-pool> tag also contains optional <resize-policy> IoC-based tag that defines object pool resizing policy to be used with this object pool.

For specifics of IoC and IoC-based configuration see IocService.

 Top

Examples
Usage of 'objpool' service follows the standard pattern of using xTier™ service: you need to obtain an instance of xTier™ kernel that serves as a service registry. Once you have xTier™ kernel you can get an instance of any service, in our case the object pool service. Once the service instance is obtained the service API can be used. The following code snippet illustrates the basic usage pattern for the 'objpool' service:

1// Get the instance of xTier kernel.
2XtierKernel xtier = XtierKernel.getInstance();
3 
4// Get the instance of 'objpool' service.
5objpool = xtier.objpool();
6 
7// Get XML-defined object pool.
8ObjectPool pool1 = objpool.getPool("my.pool.xml");
9 
10// Create new pool at runtime.
11ObjectPool pool2 = objpool.createPool(
12    "my.pool.runtime", 
13    5, 
14    ObjectPoolService.POLICY_OVERFLOW, 
15    new FooBarFactory(), 
16    false);
17 
18// Use 'objpool' API...
19Object obj = pool2.acquire();
20...
21 
22// Delete pool from 'objpool' service.
23objpool.deletePool(pool2.getName()); 
24 
25// Get XML-defined thread pool.
26ThreadPool pool3 = objpool.getThreadPool("my.threadpool.xml");
27 
28// Creates new thread pool at runtime.
29ThreadPool pool4 = objpool.createThreadPool(
30    "my.threadpool.runtime", 
31    10, 
32    ObjectPoolService.POLICY_GROW, 
33    true, 
34    Thread.NORM_PRIORITY);
35 
36// Add test task for execution on thread pool.
37pool4.addTask(new Runnable() {
38  public void run() {
39    // Task body.
40    ...
41  }
42});
43...
44 
45// Delete thread pool from object pool service and 
46// wait for the task to complete.
47objpool.deleteWaitThreadPool(pool4.getName());

 Download xTier™ for full examples and documentation.

 Top

spacer