Hi,

I have a servlet as a front component in my webapp; the servlet has also the
task of saving a Object in static variable (for example : a integer value )
during his inizialization.
When I start orion server, I set new value for static variable (for example
new value = 20 )
and I call the servlet  n  times ( n >= 2 ) I see 2 servlet instance created
(see the output below)

Please help me, how to make only 1 servlet instance.

I have done a small example so that i can explain me in a more clear way :

my web.xml
  <servlet>     
                <servlet-name>MyServlet</servlet-name>
                <servlet-class>MyServlet</servlet-class>
                <load-on-startup>0</load-on-startup>
   </servlet>

the code of the my object is
class  MyObject extends Object {
        private static int myvar = 10;
        public static void setVar(int var) {
                myvar = var;
        }
        public void myprint() {
                System.out.println("I'm a Object : " + this + " and my
variable : " + myvar);
        }
}

the code of the servlet is: 
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class MyServlet extends HttpServlet {
    public void init(ServletConfig conf) throws ServletException {
                MyObject myObject = new MyObject();
                myObject.myprint();
                MyObject.setVar(20);
                System.out.println("Done " + this);
    }
        public void service(HttpServletRequest request, HttpServletResponse
response)
          throws ServletException, IOException  {
        doGet( request, response );         
        }
        public void doGet(HttpServletRequest request, HttpServletResponse
response)
          throws ServletException, IOException {
        }
        public void doPost(HttpServletRequest request, HttpServletResponse
response)
          throws ServletException, IOException {
            doGet( request, response );     
        }
}

now, if I start the server & i call the servlet n times (n >= 2 ) i can see
2 servlet instance created (see the output below) 
D:\webserver\Orion>java -jar orion.jar
I'm a Object : MyObject@7c1f2a88 and my variable : 10
Done MyServlet@66732a88
Orion/1.4.4 initialized
I'm a Object : MyObject@e86f2a8a and my variable : 10
Done MyServlet@c34f2a8a


I using Orion server 1.44,  and Please help me, how to make only 1 servlet
instance.
Thanks,
Phong Quoc Tran



===========================================
Tran Quoc Phong

Paragon Solutions Vietnam (PSV)
26-28 Dong Du Street, District 1, HoChiMinh City, Vietnam
Phone          : (84-8) 8 251 250  (ext 181 or 182)
Office email  : [EMAIL PROTECTED]
Private email : [EMAIL PROTECTED]
Web site      : http://www.psv.com.vn

Reply via email to