I tend to think that Singletons are overused, and often indicate a flaw with the basic architecture of a solution. Assuming you've done enough analysis to prove you need a Singleton, you can use an older Singleton pattern that doesn't rely on static initialization. Here's an example:
public SomeServlet extends HttpServlet {
private instance = null;
private SomeServlet() {
// Construction code here
}
public synchronized SomeServlet getInstance() {
if(instance == null) {
instance = SomeServlet();
}
return instance;
}
// Servlet methods here
}
I see two potential problems though:
First, you'll need a wrapper Servlet (or maybe just chain from another servlet, since the Servlet container won't know how to deal with not having a private constructor.
Second, you'll still need to synchronize the servlet methods because you still can't guarantee that there's only one executor thread "in" the servlet at a time.