This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
I built a web application with a mail deamon thread. Mail deamon code like the following: public class MailDeamon extends Thread { public MailDeamon(Runnable target) { super(target); } private static MailDeamon deamon = new MailDeamon(new MailRun()); ................... public static void begin() { deamon.start(); } static class MailRun implements Runnable { public void run() { logger.debug("Deamon[" + deamon.hashCode() + "] begin at " + (new Date())); while (true) { try { doit(); Thread.sleep(fequence); } catch (InterruptedException ex) { logger.error(ex); } } } private void doit() { logger.debug("Run deamon at " + new Date()); } } I put is in a listener like this: <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <listener> <listener-class>com.everse.liteworkflow.service.JobListener</listener-class> </listener> public class JobListener implements ServletContextListener { public void contextDestroyed(ServletContextEvent event) { } public void contextInitialized(ServletContextEvent event) { MailDeamon.begin(); } } When I run is in tomcat I got duplicate instance of MailDeamon. The following is logger: 2008-06-10 11:00:38,828[Thread-1]{ABSOLUTE} DEBUG MailDeamon:38 - Deamon[28073747] begin at Tue Jun 10 11:00:38 GMT+08:00 2008 2008-06-10 11:00:38,828[Thread-1]{ABSOLUTE} DEBUG MailDeamon:50 - Run deamon at Tue Jun 10 11:00:38 GMT+08:00 2008 2008-06-10 11:00:41,859[Thread-10]{ABSOLUTE} DEBUG MailDeamon:38 - Deamon[7272378] begin at Tue Jun 10 11:00:41 GMT+08:00 2008 2008-06-10 11:00:41,859[Thread-10]{ABSOLUTE} DEBUG MailDeamon:50 - Run deamon at Tue Jun 10 11:00:41 GMT+08:00 2008 Deamon[28073747],Deamon[7272378] means 2 instance. But I define deamon as static object. "private static MailDeamon deamon = new MailDeamon(new MailRun());" And in the netbeans console I got some exception messages: Exception in thread "Thread-1" java.lang.NullPointerException at com.everse.liteworkflow.service.MailDeamon$MailRun.doit(MailDeamon.java:50) at com.everse.liteworkflow.service.MailDeamon$MailRun.run(MailDeamon.java:41) "MailDeamon.java:50" is "logger.debug("Run deamon at " + new Date());" In "Thread-10", "MailDeamon.java:50" running well. When I put app.war in a standalone tomcat, I got only one thread for MailDeamon and everything was running well. So I was confused why NetBeans try to start 2 threads when I run tomcat in the IDE.