Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Java Hit Counter

807588Jul 1 2009 — edited Jul 6 2009
Hello 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 ());
}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 3 2009
Added on Jul 1 2009
11 comments
307 views