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.

Bug 136871 - Tomcat thread error in NetBeans
Summary: Tomcat thread error in NetBeans
Status: NEW
Alias: None
Product: serverplugins
Classification: Unclassified
Component: Sun Webserver (show other bugs)
Version: 6.x
Hardware: All All
: P1 blocker (vote)
Assignee: issues@serverplugins
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-06-10 04:23 UTC by brianwang
Modified: 2008-06-10 04:23 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description brianwang 2008-06-10 04:23:05 UTC
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.