Re: Life span of a resource

Mike Mills writes:
 > 
 > What should one do of they require some static variable(s) on the server?
 > These may be contained in the
 > Resource class itself OR may be shared among many resources. Can I force
 > resources to be dumped so I can
 > test my server side programs? 

That one is easy:

public class SomeStaticContext {
   static WhateverObject o;

   public synchronized static getContext() {
      if ( o == null ) 
         // initialize it
      return o;
   }
}

public class MyResource extends HTTPResource {
    WhateverObject shared = null;

    public void initialize(Object values[]) {
        super.initialize(values);
        // Get access to shared object:
        shared = SomeStaticContext.getContext();
    }
        
}

You're all set (?) The initialize method is called when the resource
is being loaded. If you want to keep track of when the context is
unused (this gets a little bit trickier), you have to register a Lock
on all resources that use the same context, implement some kind of
ref-counting, and explictly call delete on the shared context when
appropriate.

Or, of course, you can rely on the finalize method (if that's enough)

 > Is there a way to see what resources are
 > currently "active"?

The ResourceStoreManager is the one that knows about this, but there
is no documented way to access to that piece of data (you can hack it
of course ;-)

Anselm.

Received on Monday, 7 October 1996 15:28:18 UTC