W3C home > Mailing lists > Public > www-jigsaw@w3.org > September to October 1996

Re: Life span of a resource

From: Anselm Baird-Smith <abaird@w3.org>
Date: Mon, 7 Oct 1996 15:28:08 -0400 (EDT)
Message-Id: <199610071928.PAA21565@anansi.w3.org>
To: Mike Mills <mmills@monmouth.com>
Cc: www-jigsaw@w3.org, mmills@shell.monmouth.com
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 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 9 April 2012 12:13:25 GMT