On Friday 06 September 2002 7:18 pm, John Walstra wrote:
> I think maybe what you're trying to do could be accomplished like this:
>
> public class LmsPage extends Page
> {
> protected static ObjectPool serverMapPool;
> static
> {
> PoolableObjectFactory serverMapFactory = new LmsServerMapFactory();
> serverMapPool = new StackObjectPool( serverMapFactory, 1000 );
> }
>
> private ServerMap serverMap = null;
>
> public LmsPage()
> {
> }
>
> public ServerMap getServerMap() throws Exception
> {
> if( serverMap == null )
> {
> serverMap = (ServerMap)serverMapPool.borrowObject();
> }
> return serverMap;
> }
>
> public void finalize() throws Throwable
> {
> super.finalize();
> if( serverMap != null )
> {
> serverMapPool.returnObject( serverMap );
> }
> }
> }
>
> I.e., make the serverMapPool a static (class-scope) variable. Then each
> instance of LmsPage will still only borrow (and cache) one serverMap
> instance, but when one LmsPage instance goes out of scope (and gets
> finalized), it will return this cached instance to the pool. Later
> instances of LmsPage can then reuse that instnace LmsServerMap by borrowing
> it from their shared pool.
Works, with a little modification. I had to remove the clearing of the map, it
was causing NullPointerExceptions since it's only reloads the info if map
points to null. I basically was clearing the map, not reloading, then trying
to access information.
/**
* Uninitialize an instance to be returned to the pool.
* @param obj the instance to be passivated
*/
public void passivateObject(Object obj)
throws Exception
{
// Map map = (Map)obj;
// map.clear();
}
Thanks for help,
John
--
John Walstra
[EMAIL PROTECTED]
There are more dead people than living, and their numbers are increasing.
-- Eugene Ionesco
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>