Hi,

Two things.
1) Your servlet implements SingleThreadModel -- which means Tomcat *may*
create multiple instances of your class -- how do other servlets get hold
of the instance? The public method is not static - did you mean it to be?

2) In order to flush the (instance) variables to other threads (according
to the Java memory model)  your should synchronize all access to them.

Ken.





[EMAIL PROTECTED] on 12/07/2001 13:50:11

Please respond to [EMAIL PROTECTED]; Please respond to
      [EMAIL PROTECTED]

To:   [EMAIL PROTECTED]
cc:    (bcc: Ken X Horn)
Subject:  Hello !



I am a new user in this list, and i'm French so please forgive my
mistakes !

I am developing a project with Tomcat and servlets technology, and i
have the following problem i would like to submit to you:

I have a basic servlet S1 who includes several methods useful for all
the other servlets.
The appli works fine... but suddenly, i get a loss of context that i
can't explain.
One of the servlets who calls a S1's method sees all the global
variables have a NULL value, while a few moments before these values
were correctly defined.
These values are config parameters read from the web.xml file of the
appli. They are initialized in the init() method of the S1 servlet.

So i wonder what's going on...
Is there any config or servlet memory timeout that raises ? or what ?...

It is a serious problem because all the application becomes
unpredictably unusable, until i restart Tomcat.

Here is a bit of my S1 servlet code :

/**************************************************************
public class S1 extends HttpServlet implements SingleThreadModel {

private static String P1;
...

//------------------------------------------------------------------------------------


// methode d'initialisation: recuperation des parametres de conf
public void init(ServletConfig sc) throws ServletException {

 if (sc == null) {
 System.out.println("ServletConfig = null");
 System.exit(1);
 }

 super.init(sc);
 try {
 P1 = sc.getInitParameter("P1");
...

 if (P1 == null) {
  System.out.println("Paramètres de configuration de l'application
incorrectement renseignés.");
  System.exit(1);
 }
 else System.out.println("Contexte Base de signalements chargé.");
 }
 catch (Exception e) {
 e.printStackTrace();
 System.out.println("Lecture des paramètres de configuration de
l'application impossible.");
 System.exit(1);
 }
}

// method called by other servlets
public String m1(ServletOutputStream out) {

// uses init parameters such as P1 and returns a result
...
}
/**************************************************************

thanks for any help

Stéphane







Reply via email to