axis-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Keith Hatton" <khat...@axiomsystems.com>
Subject RE: What happens to Java objects when Axis is reloaded by Tomcat?
Date Thu, 22 Jul 2004 11:49:36 GMT
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 
calls can access the same object.  Things work fine until Axis is reloaded 
(by Tomcat web app manager).  I can no longer get a handle on the original 
singleton, instead a new singleton is created.

I wouldn't mind this behavior if the original singleton was cleaned up, but 
instead it sticks around.  I know this because I have threads that are still 
able to see the original singleton.  So what I end up with is multiple 
singletons, one for every time Axis is reloaded and no way of getting a 
handle on the old singletons.  The only way I can get rid of them is to 
restart Tomcat.

What happens when Axis is reloaded by Tomcat?
Is there any way to have the singleton objects and threads that were 
associated with Axis before the reload get cleaned up?  Or a way to get a 
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 
value. */
    public String
    showAndSet (String newValue)
    {
        String originalValue = Singleton.getInstance().getValue();
        Singleton.getInstance().setValue(newValue);
        return (originalValue);
    }
}


/** Singleton.java */
public class Singleton
{
    private static Singleton singleton = null;
    private String value = "unset";

    /** Singleton so constructor is private. */
    private
    Singleton()
    {
    }

    public static Singleton
    getInstance()
    {
        if (singleton == null) {
            singleton = new Singleton();
        }
        return (singleton);
    }

    public String
    getValue()
    {
        return (value);
    }

    public void
    setValue (String newValue)
    {
        value = 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 = "http://localhost:8080/axis/SingletonTest.jws";

        if (args == null || args.length < 1) {
            System.err.println("Usage: SingletonTestClient <name>");
            return;
        }

        String value = args[0];
        String retStr = null;
        Object [] objs = null;

        Service  service = new Service();
        Call     call    = (Call) service.createCall();

        call.addParameter ("showAndSet", XMLType.XSD_STRING, 
ParameterMode.IN );
        objs = new Object [] { value };

        call.setTargetEndpointAddress( new java.net.URL(endpoint) );
        call.setOperationName("showAndSet");
        call.setReturnType(XMLType.XSD_STRING);

        retStr = (String) call.invoke(objs);
        System.out.println("Result: " + retStr);
    }
}

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE! 
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/


Mime
View raw message