You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by "Agarwal, Naresh" <na...@informatica.com> on 2003/07/01 07:17:08 UTC

RE: Service Class as Singleton Class

Hi Aaron/Niket,

I believe you can tackle this problem by having your service class deployed in
"application" scope in AXIS. 

Internally AXIS will make sure that only once instance of this service class would
serve all the request during the life time of Tomcat (or the servlet container used).

regards,
Naresh Agarwal

-----Original Message-----
From: Aaron Knauf [mailto:aknauf@xtra.co.nz]
Sent: Tuesday, May 27, 2003 10:06 AM
To: axis-dev@ws.apache.org
Subject: Re: Service Class as Singleton Class


The problem is that Axis instantiates and new service class instance 
each time the service is invoked, using reflection to find the public 
constructor.  It would be difficult to get Axis to cater for singletons, 
as the getInstance method could be called anything.

I found the instantiation of a new service class for each invocation to 
be a problem, so I worked around it by implementing my service class as 
a proxy to a singleton implementation class.  The wrapper gets 
instantiated every time, but the class that implements all the logic is 
only instantiated once.  This was to avoid expensive initialization code 
(such as starting up a pool of connections to a CORBA server) from being 
executed repeatedly, but it had the handy side effect of allowing me to 
read in my config from the WSDD file in this wrapper, too, therby hiding 
the fact that the thing was running as a web service from the impl class.

Hope this helps.

Cheers

ADK

Niket Anand wrote:

>  
>
>
>     Hello All,
>     I am newbie to Axis. I am facing problem as
>     java.lang.InstantiationException
>     <file:///C:/jdk1.3.1/docs/api/java/lang/InstantiationException.html>
>     exception when my service class is Singleton class and having
>     private constructor and getInstance() to get instance of this
>     class. When axis client ask for a method from the service class
>     then it throw this exception. If I remove the Singleton ability
>     and provide public constructor then it works fine. But I want it
>     to be remain Singleton . Please help me How to work with Service
>     class as Singleton and what modification needs to be done in wsdd.
>      
>     waiting for reply...
>     thanks,
>     Niket
>