[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index] [Home]

Re: bean reloading



Here is the example. First the bean:
-----------------
package temp;

import javax.servlet.*;  

public class App implements Runnable {
   static Thread t = null;
   static String name = null;
   static ServletContext sContext = null;

   public App() {

   }

   public void init(ServletContext context, String name) {
      this.name = name;
      if (sContext == null) {
         sContext = context;
         log("app initialized: " + name);
         if (t == null) {
            t = new Thread(this);
            t.setDaemon(true);
            t.start();
         }
      }
   }

   public void run() {
      while(true) {
         log("Hello, I'm thread: " + name);
         try {
            Thread.sleep(10000);
         } catch (InterruptedException e) {}
      }
   }

   private static void log(String message) {
      if (sContext != null) sContext.log(message);
      else System.out.println(message);
   }

   /*public static void main(String[] args) {
      new App();
   } */
}
--------------
Even if I tried a static variable Thread, it didn't work - it DID initialize
the thread anyway when the bean was reloaded, but it shouldn't because the
variable is static and thus not null (thread already started). Daemon thread
should be cleaned up when the instance class is. The same happens with an
ordinary thread.

Now the JSP:
----------------------
<jsp:useBean id="test" scope="application" class="temp.App" />
<% test.init(application,"2"); %>

Thread started.
------------------------


I got this in my log:
[25/10/1999 14:51:34:370 GMT+02:00] ApacheJServ/1.0 is starting...
[25/10/1999 14:51:34:370 GMT+02:00] WARNING: connection authentication is
disabled
[25/10/1999 14:51:34:411 GMT+02:00] Connection allowed from localhost/127.0.0.1
[25/10/1999 14:51:34:411 GMT+02:00] Listening on port 8007 accepting 50 maximum
connections
[25/10/1999 14:51:34:421 GMT+02:00] Creating Servlet Zones
[25/10/1999 14:51:36:594 GMT+02:00] gnujsp/org.gjt.jsp.JspServlet: init
[25/10/1999 14:51:40:549 GMT+02:00] gnujsp/jsp___2fthread_2ejsp: init
[25/10/1999 14:51:40:599 GMT+02:00] gnujsp/app initialized: 2
[25/10/1999 14:51:40:629 GMT+02:00] gnujsp/Hello, I'm thread: 2
[25/10/1999 14:51:50:624 GMT+02:00] gnujsp/Hello, I'm thread: 2
[25/10/1999 14:52:00:628 GMT+02:00] gnujsp/Hello, I'm thread: 2

then I touched the class and changed the second init parameter to 1 in the JSP. 

[25/10/1999 14:52:23:721 GMT+02:00] gnujsp/org.gjt.jsp.JspServlet: destroy
[25/10/1999 14:52:23:721 GMT+02:00] java.lang.NullPointerException
	at org.gjt.jsp.JspServlet.destroy(Compiled Code)
	at org.apache.jserv.JServServletManager.destroyServlet(Compiled Code)
	at org.apache.jserv.JServServletManager.destroyServlets(Compiled Code)
	at org.apache.jserv.JServServletManager.checkReload(JServServletManager.java)
	at org.apache.jserv.JServConnection.processRequest(JServConnection.java)
	at org.apache.jserv.JServConnection.run(JServConnection.java)
	at java.lang.Thread.run(Thread.java:466)
[25/10/1999 14:52:24:082 GMT+02:00] gnujsp/org.gjt.jsp.JspServlet: init
[25/10/1999 14:52:25:424 GMT+02:00] gnujsp/jsp___2fthread_2ejsp: init
[25/10/1999 14:52:25:444 GMT+02:00] gnujsp/app initialized: 1
[25/10/1999 14:52:25:464 GMT+02:00] gnujsp/Hello, I'm thread: 1
[25/10/1999 14:52:30:631 GMT+02:00] gnujsp/Hello, I'm thread: 2
[25/10/1999 14:52:35:468 GMT+02:00] gnujsp/Hello, I'm thread: 1
[25/10/1999 14:52:40:636 GMT+02:00] gnujsp/Hello, I'm thread: 2
[25/10/1999 14:52:45:473 GMT+02:00] gnujsp/Hello, I'm thread: 1
[25/10/1999 14:52:50:640 GMT+02:00] gnujsp/Hello, I'm thread: 2

If I changed only the jsp, then no new thread was started:

[25/10/1999 14:47:52:231 GMT+02:00] gnujsp/app initialized: 1
[25/10/1999 14:47:52:241 GMT+02:00] gnujsp/Hello, I'm thread: 1
[25/10/1999 14:48:02:235 GMT+02:00] gnujsp/Hello, I'm thread: 1
[25/10/1999 14:48:12:240 GMT+02:00] gnujsp/Hello, I'm thread: 1
[25/10/1999 14:48:22:244 GMT+02:00] gnujsp/Hello, I'm thread: 1
[25/10/1999 14:48:32:249 GMT+02:00] gnujsp/Hello, I'm thread: 1
[25/10/1999 14:48:33:160 GMT+02:00] gnujsp/jsp___2fthread_2ejsp: init
[25/10/1999 14:48:42:243 GMT+02:00] gnujsp/Hello, I'm thread: 1
[25/10/1999 14:48:52:247 GMT+02:00] gnujsp/Hello, I'm thread: 1
[25/10/1999 14:49:02:252 GMT+02:00] gnujsp/Hello, I'm thread: 1
[25/10/1999 14:49:12:246 GMT+02:00] gnujsp/Hello, I'm thread: 1
[25/10/1999 14:49:22:251 GMT+02:00] gnujsp/Hello, I'm thread: 1


By the way, is it possible to redirect JServ log to console instead of into a
file on Win NT ? Or does a program like 'tail' on Unix exist for win NT
somewhere?


Primoz

Carsten Heyl wrote:
> 
> >
> >I am using application scoped bean, which uses a daemon thread.  If I put the
> >classpath of this bean into my JServ repository, it is reloaded correctly when
> >it is changed, however the thread does not stop and remains running, although
> >the new bean is initialized, which thus starts a new thread. I end up with two
> >threads running in the background, but there should be only one. I use GNU JSP
> >1.0 and JServ 1.0.
> 
> Could you send us a small example?
> I'm not sure what happens with application scoped beans if the
> bean class changes. I thought the bean object won't change because
> a pointer to it exists in the ServletContext.
> But I need a small example to make sure we're talking about the
> same things.
> 
> >
> >
> >Any thoughts on this?
> >
> >Primoz
> >
> 
> Ciao,
>         Carsten
> alph@gjt.org