Hi had the same problem & i resolved with a static Object working as a lock
in the init method. 
The best thing however is to upgrade to 1.4.7 wich does not present this
strange behaviour anymore.

Marco

-----Messaggio originale-----
Da: Vinh Chu Xuan [mailto:[EMAIL PROTECTED]]
Inviato: lunedì, 26. febbraio 2001 17:06
A: Orion-Interest
Oggetto: Re: Servlet loading twice, Help me, please


Hi Phong,
I am now at home,so i do not have the source code here.
In this case you should use global Java Bean.
I will send you the sample.
Hope that will help you.
Talk to you later.
Best regards,
Vinh Chu Xuan
Vietnam Data Communication Company
Software R&D Department
1E Truong Chinh - Hanoi - Vietnam
http://home.vnn.vn/vdc/index_e.html
Office : +84 4 8699112-307
Cell phone : +84 91 21 6116

----- Original Message -----
From: Phong Quoc Tran <[EMAIL PROTECTED]>
To: Orion-Interest <[EMAIL PROTECTED]>
Sent: Monday, February 26, 2001 8:37 AM
Subject: Servlet loading twice, Help me, please


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