Java Hit Counter
807588Jul 1 2009 — edited Jul 6 2009Hello Every1
Every time I run the MessageCounter class I get the following result
total messages : 1
Problem : The counter is not incrementing after each run , printing the same result " total messages : 1"
Any thought?
Thanks
Code below:
public final class Counter {
private static int messageCounter=0;
private static final class SingletonHolder {
static final Counter singleton =new Counter();}
private Counter() {}
public static Counter getInstance() {return SingletonHolder.singleton;}
public synchronized void increment () {
synchronized( Counter.class) { ++messageCounter; }
System.out.println(" total messages : " + messageCounter);}
}
public class BSMMessageCounter implements Serializable {
private BSMMessageCounter( incrementCounter();) {}
public synchronized void incrementCounter() throws Exception{
System.out.println(" total messages : " + CCounter.getInstance().increment ());
}
}