First of all your orion startup servlet only needs the service method.

And then it should be <load-on-startup> x </load-on-startup> ( see web.xml)

where x is an appropiate nr.

This will force orion to load it before it is fully inited.

regards


Johan

( my servlet that loads up data from database takes between 15 sek - 240 sek
depending on the connection and I never had any problems with two
instances...)


----- Original Message -----
From: "Marco Isella" <[EMAIL PROTECTED]>
To: "Orion-Interest" <[EMAIL PROTECTED]>
Sent: Wednesday, January 31, 2001 10:40 PM
Subject: Servlet loading twice if init() not finished?


> Hi,
>
> i have a servlet as a front component in my webapp; the servlet has also
the
> task of loading objects from a db during his inizialization. Loading the
> objects takes some time & i have encountered a situation wich i didn't
> expected & wich i'm not sure if i'm doing something wrong or it is orion.
> The situation is that if orion recive a request wich point to the servlet
> before the servlet has finished the init() method (wich was triggered from
a
> previous request) it creates another instance of the servlet.
>
> I have done a small example so that i can explain me in a more clear way :
>
> in my web.xml file i have defined &  mapped the servlet:
> <servlet>
> <servlet-name>testServlet</servlet-name>
> <servlet-class>TestServlet</servlet-class>
> </servlet>
> <servlet-mapping>
> <servlet-name>testServlet</servlet-name>
> <url-pattern>/test</url-pattern>
> </servlet-mapping>
>
> the code of the servlet is:
>
> import java.io.*;
> import java.util.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
> public class TestServlet extends HttpServlet {
>     public void doPost(HttpServletRequest req, HttpServletResponse res)
> throws ServletException, IOException {
>         doGet(req, res);
>     }
>     public void doGet(HttpServletRequest req, HttpServletResponse res)
> throws ServletException, IOException {
>         System.out.println("doGet()");
>     }
>     public void init() {
>         System.out.println("init() " +this);
>         try {
>             Thread.currentThread().sleep(5000);    // this is for
simulating
> the time consuming task
>         } catch (Exception e) {}
>         System.out.println("done! " + this);
>     }
> }
>
> now, if I start the server & i call the servlet 2 times (the second before
> init() finish) i can see 2 servlet instance created (see the output below)
>
> D:\orion>java -jar d:/orion/orion.jar
> Orion/1.4.5 initialized
> init() TestServlet@704baa
> init() TestServlet@34fad5
> done! TestServlet@704baa
> doGet()
> done! TestServlet@34fad5
> doGet()
>
> wich is not really what i want(& expected). I haven't watched the specs so
> i'm not sure if this is the correct behavior in a situation like that & i
> would like to know what u people think about it.
> If someone has also a workaround it will be very much appreciated.. ;)
>
> I'm running orion on w2k (i tried 1.4.5 & 1.4.4, same behaviour for both).
> Marco
>
>
>
> --
>
> Ing. Marco Isella, Software Engineer
> TINET SA, Via Violino 1, CH-6928 Manno-Lugano
> tel. +41 91 612 22 22, fax. +41 91 612 22 23
> email [EMAIL PROTECTED]
> http://www.tinet.com
>


Reply via email to