jQuery in Action, 3rd edition
The moose likes Servlets and the fly likes Singleton implemented using Servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Singleton implemented using Servlets" Watch "Singleton implemented using Servlets" New topic

Singleton implemented using Servlets

jeff wisgo

Joined: Apr 20, 2004
Posts: 15
I am trying to create only a single instance of a class which will run once Jakarta-Tomcat begins execution. To do this I have the following code:




When I run Jakarta-Tomcat, I can see the Daemon writing once every ~1 minute as expected. However, when I run other Servlets (which aren't related to this) there are additional instances of the Daemon which are apparently created, because I see many writes to the logfile, sometimes only 1 second apart. It seems like the init() function is being called again even though I t should not be.

Can anyone help out?

[ October 01, 2004: Message edited by: jeff wisgo ]
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63349

I do not know what is causing your problem, but you might want to look into using context listeners to perform single-shot startup/shutdown actions rather than servlets.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
jeff wisgo

Joined: Apr 20, 2004
Posts: 15
After doing some more research, it appears that the problem may be related to multiple class loaders, does anyone the semantics of how class loaders interact with Tomcat?
I agree. Here's the link: http://aspose.com/file-tools
subject: Singleton implemented using Servlets
It's not a secret anymore!