You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Artur Rataj <ar...@gmail.com> on 2006/02/22 17:33:07 UTC

STrange problem with a thread made in Servlet.init()

I made a servlet that starts on startup, and in its init() method a
new thread is started. The thread reads from a FS and uses JDBC, yet,
it does not work, as many errors similar to that occur:

Feb 22, 2006 5:26:27 PM org.apache.catalina.loader.WebappClassLoader loadClass
INFO: Illegal access: this web application instance has been stopped
already.  Could not load java.util.Scanner.  The eventual following
stack trace is caused by an error thrown for debugging purposes as
well as to attempt to terminate the thread which caused the illegal
access, and has no functional impact.
java.lang.IllegalStateException
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1238)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1198)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
        at org.algstoch.trafficlogger.Logger.<init>(Logger.java:50)
        at logger.LoggerThread.run(LoggerThread.java:35)


If the same thread is run outside webapp, it works ok.

What can it be?

Best regards,
Artur

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: STrange problem with a thread made in Servlet.init()

Posted by Artur Rataj <ar...@gmail.com>.
I replaced HttpServlet.init() with a listener, do both
startup/shutdown of the thread, and also shut down HSQLDB not before
VM shutdown, but in the listener. And now the thread works OK, and
these error messages are gone.

Best regards,
Artur

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: STrange problem with a thread made in Servlet.init()

Posted by Artur Rataj <ar...@gmail.com>.
On 2/22/06, David Smith <dn...@cornell.edu> wrote:
> Hmmm.... A very verbose exception message.  Can we see the code that
> threw the exception?  Are there any other exceptions in the logs before
> this one?
>

There is a servlet that loads on start up. In its init(ServletConfig
config) is a code starting a new thread:

        LoggerThread loggerThread = new LoggerThread();
        loggerThread.start();

the run() method of the LoggerThread is as follows:

    public void run() {
        try {
            try {
                String fifoName = MapTable.get("tlog_conf", "feed-fifo");
                System.out.println("LoggerThread: feed fifo name is `"
+ fifoName + "'");
                Logger logger = new Logger(fifoName, 1000*10);
            } catch(IOException e) {
                throw new IOException("Could not start traffic logger
thread: " + e.toString());
            } catch(SQLException e) {
                throw new IOException("Could not start traffic logger
thread: " + e.toString());
            }
        } catch(IOException e) {
            System.out.println(e.toString());
        }
    }

It is being developed, and no proper error handling is done yet.

The constructor of Logger is in an infinite loop that scans fifo
output. The last line of the code shown causes the error:

    public Logger(String namedPipe, int reportPeriod) throws
            IOException {
        InputStream in;
        try {
            in = new FileInputStream(namedPipe);
        } catch(FileNotFoundException e) {
            throw new IOException("Could not open pipe: " +
                    e.toString());
        }
        Scanner scanner = new Scanner(in);

The catalina.out log up to the error is as follows:

Feb 22, 2006 5:26:02 PM org.apache.coyote.http11.Http11BaseProtocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Feb 22, 2006 5:26:02 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1852 ms
Feb 22, 2006 5:26:02 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Feb 22, 2006 5:26:02 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/5.5.15
Feb 22, 2006 5:26:02 PM org.apache.catalina.core.StandardHost start
INFO: XML validation disabled
LoggerThread: feed fifo name is `/home/art/fifo'
Exception in thread "HSQLDB Timer @dc57db" java.lang.NullPointerException
        at org.hsqldb.lib.HsqlTimer.nextTask(Unknown Source)
        at org.hsqldb.lib.HsqlTimer$TaskRunner.run(Unknown Source)
        at java.lang.Thread.run(Thread.java:595)
Feb 22, 2006 5:26:07 PM org.apache.coyote.http11.Http11BaseProtocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Feb 22, 2006 5:26:07 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Feb 22, 2006 5:26:07 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/50  config=null
Feb 22, 2006 5:26:07 PM org.apache.catalina.storeconfig.StoreLoader load
INFO: Find registry server-registry.xml at classpath resource
Feb 22, 2006 5:26:07 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 5577 ms

As you can see, HSQLDB, that worked correctly before adding the
thread, started to misbehave for some reason, too.

Best regards,
Artur

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: STrange problem with a thread made in Servlet.init()

Posted by David Smith <dn...@cornell.edu>.
Hmmm.... A very verbose exception message.  Can we see the code that 
threw the exception?  Are there any other exceptions in the logs before 
this one?

--David

Artur Rataj wrote:
> I made a servlet that starts on startup, and in its init() method a
> new thread is started. The thread reads from a FS and uses JDBC, yet,
> it does not work, as many errors similar to that occur:
>
> Feb 22, 2006 5:26:27 PM org.apache.catalina.loader.WebappClassLoader loadClass
> INFO: Illegal access: this web application instance has been stopped
> already.  Could not load java.util.Scanner.  The eventual following
> stack trace is caused by an error thrown for debugging purposes as
> well as to attempt to terminate the thread which caused the illegal
> access, and has no functional impact.
> java.lang.IllegalStateException
>         at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1238)
>         at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1198)
>         at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
>         at org.algstoch.trafficlogger.Logger.<init>(Logger.java:50)
>         at logger.LoggerThread.run(LoggerThread.java:35)
>
>
> If the same thread is run outside webapp, it works ok.
>
> What can it be?
>
> Best regards,
> Artur
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>   

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org