----- Original Message ----- From: "ktou Ho" <[EMAIL PROTECTED]>
To: <users@tomcat.apache.org>
Sent: Thursday, June 05, 2008 12:14 AM
Subject: Singleton in Tomcat 6.0 not working



Hi,
I am using Tomcat 6.0.16 with JDK 1.6. I created a web application and deployed it as ROOT. (I removed the default ROOT which comes with tomcat). The problem I am facing is the Singleton is not working at all in the servlet. I tried to synchnozed the constructor or make it static. I still get two instances of the objects. How can I solve the problem?

e.g.
=======
public class RemoteDBConnections
{
private static RemoteDBConnections sInstance = new RemoteDBConnections();
   private static int counter=0;

   private RemoteDBConnections()
   {
       System.out.println("counter =" + (counter++));

   };

   public  static synchronized RemoteDBConnections getInstance()
   {
       return sInstance;
   }
}
======
Thanks in advance
Elwin

--------------------------------------------------
Looks good to me... cant see anything wrong
Maybe the call is wrong

Should be
RemoteDBConnections obj = RemoteDBConnections.getInstance();

Doing
RemoteDBConnections obj = new RemoteDBConnections().getInstance();
would make 2 counters

Maybe you just slipped in the call... but even then counter will clock twice but instance will just be one.
Maybe... guessing ;)

Give Up ;)



---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to