Have your listener instantiate them into a static context class (of
your divination), and then pull them out of that with CFMX as needed,
almost certainly via a context CFC that wraps the context class:

public class MyListener ... {
  ... contextInitialized() {
    MyJavaContext.setObjectOne(new WhateverObject());
    ...
  }
}

public class MyJavaContext ... {
  private static Object objectOne;
  public static void setObjectOne(Object oo) {
    objectOne = oo;
  }
  public static Object getObjectOne() {
    return objectOne;
  }
}

<cfcomponent displayName="MyCfmxContext">
  <cffunction name="getObjectOne" ... >
    <cfreturn createObject("java", "MyJavaContext").getObjectOne() />
  </cffunction>
</cfcomponent>

Note that a hard kill of the web container (e.g. JVM segfaults) isn't
going to get to destroy the objects nicely, but there isn't really a
way around that.

Another, quite possibly better, would be to just use
onApplicationStart and onApplicationEnd in Application.cfc to either
instantiate the three objects, or use a CFLOCK to instantiate them
into the server scope safely for access by multiple applications.
You'd still want a CFC context as before, but it'd be a lot simpler,
as it'd be accessing standard CF objects.

cheers,
barneyb

On 8/12/06, David Murphy <[EMAIL PROTECTED]> wrote:
> Hello
>
> I've setup a listener that performs some housekeeping when CFMX starts up or 
> shuts down using the contextDestroyed / contextInitialized methods.
>
> I need to be able to instatiate 3 single java objects upon CFMX startup and 
> then make them globally available to be shared within CFMX. When CFMX shuts 
> down I need to be able to call methods on those 3 objects to perform tidy-up 
> tasks before cleanly shutting them down.
>
> I was thinking of storing these shared objects in the ServletContext object 
> but I was hoping to first get some guidance on how best to approach this?
>
> Many thanks, David
>
-- 
Barney Boisvert
[EMAIL PROTECTED]
360.319.6145
http://www.barneyb.com/

Got Gmail? I have 100 invites.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting,
up-to-date ColdFusion information by your peers, delivered to your door four 
times a year.
http://www.fusionauthority.com/quarterly

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:249668
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to