Restarting Jetty can cause an exception

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Restarting Jetty can cause an exception

Russell Neufeld
Using Jetty 5.1.2.  I don't have a simple test case to reproduce this, but here are the steps and the apparent fix.  Supposed you have a jetty server running and you want to stop it and start it again in the same thread.  I start jetty by doing this:

Server server = new Server()
server.configure(jettyConfigFile);
server.start();

Later, for reasons I won't go into, I need to stop the old instance and start a new one.  This code I use is:

server.stop(false);
server.destroy();

Server server = new Server()
server.configure(jettyConfigFile);
server.start();

This occasionally causes the exception

java.io.IOException Jetty configuration problem: java.lang.NullPointerException
    at org.mortbay.jetty.Server.configure(Server.java:162)
    ...

which is actually coming from the fact that the field '_parent' is null in org.mortbay.http.ContextLoader.loadClass().  For me it's line 202 which looks like
                c= _parent.loadClass(name);

This is because the class loader assigned to the current thread was destroyed in the server.stop() call, but I think it's still accessible from the current thread from Thread.currentThread().getContextClassLoader().  (See org.mortbay.util.Loader line 42.)  I was able to work around this problem by inserting the line

Thread.currentThread().setContextClassLoader(null);

after the server.destroy() and before the "new Server()" line.  I'm guessing Jetty isn't cleaning up context class loaders properly.

Any thoughts?  Thanks,

    Russ
Reply | Threaded
Open this post in threaded view
|

Re: Restarting Jetty can cause an exception

Greg Wilkins-5

I believe this is fixed in 5.1.4rc0 and there is further related issue in
CVS head at the moment.

cheers



Russell Neufeld wrote:

> Using Jetty 5.1.2.  I don't have a simple test case to reproduce this,
> but here are the steps and the apparent fix.  Supposed you have a jetty
> server running and you want to stop it and start it again in the same
> thread.  I start jetty by doing this:
>
> Server server = new Server()
> server.configure(jettyConfigFile);
> server.start();
>
> Later, for reasons I won't go into, I need to stop the old instance and
> start a new one.  This code I use is:
>
> server.stop(false);
> server.destroy();
>
> Server server = new Server()
> server.configure(jettyConfigFile);
> server.start();
>
> This occasionally causes the exception
>
> java.io.IOException Jetty configuration problem:
> java.lang.NullPointerException
>     at org.mortbay.jetty.Server.configure(Server.java:162)
>     ...
>
> which is actually coming from the fact that the field '_parent' is null
> in org.mortbay.http.ContextLoader.loadClass().  For me it's line 202
> which looks like
>                 c= _parent.loadClass(name);
>
> This is because the class loader assigned to the current thread was
> destroyed in the server.stop() call, but I think it's still accessible
> from the current thread from
> Thread.currentThread().getContextClassLoader().  (See
> org.mortbay.util.Loader line 42.)  I was able to work around this
> problem by inserting the line
>
> Thread.currentThread().setContextClassLoader(null);
>
> after the server.destroy() and before the "new Server()" line.  I'm
> guessing Jetty isn't cleaning up context class loaders properly.
>
> Any thoughts?  Thanks,
>
>     Russ



-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.  How far can you shotput
a projector? How fast can you ride your desk chair down the office luge track?
If you want to score the big prize, get to know the little guy.  
Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20
_______________________________________________
Jetty-support mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jetty-support