62,615
社区成员
发帖
与我相关
我的任务
分享
public class ServletCounter {
private static Object lock = new Object();
private static ServletCounter instance = null;
private int counter;
private ServletCounter() {
counter = 0;
}
public static ServletCounter getInstance() {
if (instance==null) {
synchronized(lock) {
if (instance == null) {
instance = new ServletCounter();
}
}
}
return instance;
}
public synchronized int getCounter() {
return counter;
}
public synchronized int setCounter(int c) {
counter = c;
return counter;
}
public synchronized int incCounter() {
return (++counter);
}
public synchronized int decCounter() {
return (--counter);
}
}