views:

14

answers:

0

I have apache tomcat 6 installed as a service on my windows xp machine.
I have a class which implements ServletContextListener and it initializes a singleton required for the correct flow of the servlets (it does so on contextInitialized).
The problem I'm seeing is that when I stop the service in windows (via services.msc) and I still have open web-pages issuing requests I see this:

10/10/2010 15:56:12 org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextDestroyed()
10/10/2010 15:56:14 org.apache.catalina.core.ApplicationContext log
(A Wrapper Exception from GWT never mind)...
Caused by: java.lang.NullPointerException
at com.company.common.CompRepository.getAgentSnapshot(CompRepository.java:152)
at com.company.common.Service.polling(Service.java:148)...

Service is a servlet and the CompRepository is a singleton and the method is:

public AgentSnapshot getAgentSnapshot(final AgentId agentId) {
return image.getValidAgentSnapshot(agentId);
}

And image is a member which I suspect is nullified somehow by the shutting down of the service.
My Singleton implementation is:

private final static CompRepository INSTANCE = new CompRepository();
private boolean initialized = false;
private Image image;
public static CompRepository getInstance() { return INSTANCE; }
private CompRepository() {}
public void initialize() {
if (!initialized){
image = new Image();
initialized = true;
} }

What I don't understand is how can it be that the image member is nullified while there are still open servlets.
What am I missing?

Thanks,
Ittai