Return-Path: Delivered-To: apmail-ws-axis-user-archive@www.apache.org Received: (qmail 71878 invoked from network); 22 Jul 2004 11:50:00 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 22 Jul 2004 11:50:00 -0000 Received: (qmail 83073 invoked by uid 500); 22 Jul 2004 11:49:47 -0000 Delivered-To: apmail-ws-axis-user-archive@ws.apache.org Received: (qmail 83055 invoked by uid 500); 22 Jul 2004 11:49:46 -0000 Mailing-List: contact axis-user-help@ws.apache.org; run by ezmlm Precedence: bulk Reply-To: axis-user@ws.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list axis-user@ws.apache.org Received: (qmail 83045 invoked by uid 99); 22 Jul 2004 11:49:46 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received: from [194.42.245.4] (HELO pegasus.axiomsystems.com) (194.42.245.4) by apache.org (qpsmtpd/0.27.1) with ESMTP; Thu, 22 Jul 2004 04:49:46 -0700 content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Subject: RE: What happens to Java objects when Axis is reloaded by Tomcat? Content-Transfer-Encoding: quoted-printable X-MimeOLE: Produced By Microsoft Exchange V6.0.5762.3 Date: Thu, 22 Jul 2004 12:49:36 +0100 Message-ID: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: What happens to Java objects when Axis is reloaded by Tomcat? Thread-Index: AcRvUhGkDMgULnuqSE+4MP4APbyD5wAj1p5Q From: "Keith Hatton" To: X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N You could register a ServletContextListener (in web.xml) that calls some = cleanup code on your singleton when the web-app is destroyed. But I = don't know how this would affect your other threads, as a new = ClassLoader is created when Axis is reloaded (this is why you get = "another" singleton). If your singleton threw an exception if a method = was called after the context had been destroyed, at least you would know = what was happening. Keith -----Original Message----- From: Donald Gorgonzola [mailto:donzola@hotmail.com] Sent: 21 July 2004 19:39 To: axis-user@ws.apache.org Subject: What happens to Java objects when Axis is reloaded by Tomcat? >From a web service call I access a singleton, so subsequent web service=20 calls can access the same object. Things work fine until Axis is = reloaded=20 (by Tomcat web app manager). I can no longer get a handle on the = original=20 singleton, instead a new singleton is created. I wouldn't mind this behavior if the original singleton was cleaned up, = but=20 instead it sticks around. I know this because I have threads that are = still=20 able to see the original singleton. So what I end up with is multiple=20 singletons, one for every time Axis is reloaded and no way of getting a=20 handle on the old singletons. The only way I can get rid of them is to=20 restart Tomcat. What happens when Axis is reloaded by Tomcat? Is there any way to have the singleton objects and threads that were=20 associated with Axis before the reload get cleaned up? Or a way to get = a=20 handle on these old objects? I am using Axis 1.1 with Tomcat 5.0.25 and Java 1.4.2. Here is some code that calls a web service that accesses a singleton. /* * SingletonTest.jws * Tests accessing a singleton from a web service call. */ public class SingletonTest { /** Shows the current value of the singleton and updates with the = new=20 value. */ public String showAndSet (String newValue) { String originalValue =3D Singleton.getInstance().getValue(); Singleton.getInstance().setValue(newValue); return (originalValue); } } /** Singleton.java */ public class Singleton { private static Singleton singleton =3D null; private String value =3D "unset"; /** Singleton so constructor is private. */ private Singleton() { } public static Singleton getInstance() { if (singleton =3D=3D null) { singleton =3D new Singleton(); } return (singleton); } public String getValue() { return (value); } public void setValue (String newValue) { value =3D newValue; } } /* * SingletonTestClient.java * Test client used to test SingletonTest.jws. */ import org.apache.axis.client.Call; import org.apache.axis.client.Service; import org.apache.axis.encoding.XMLType; import javax.xml.rpc.ParameterMode; public class SingletonTestClient { public static void main(String [] args) throws Exception { String endpoint =3D = "http://localhost:8080/axis/SingletonTest.jws"; if (args =3D=3D null || args.length < 1) { System.err.println("Usage: SingletonTestClient "); return; } String value =3D args[0]; String retStr =3D null; Object [] objs =3D null; Service service =3D new Service(); Call call =3D (Call) service.createCall(); call.addParameter ("showAndSet", XMLType.XSD_STRING,=20 ParameterMode.IN ); objs =3D new Object [] { value }; call.setTargetEndpointAddress( new java.net.URL(endpoint) ); call.setOperationName("showAndSet"); call.setReturnType(XMLType.XSD_STRING); retStr =3D (String) call.invoke(objs); System.out.println("Result: " + retStr); } } _________________________________________________________________ Express yourself instantly with MSN Messenger! Download today - it's = FREE!=20 http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/