KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openlaszlo > utils > ThreadSafeCounter


1 /* ****************************************************************************
2  * ObjectCounter.java
3  * ****************************************************************************/

4
5 /* J_LZ_COPYRIGHT_BEGIN *******************************************************
6 * Copyright 2001-2004 Laszlo Systems, Inc. All Rights Reserved. *
7 * Use is subject to license terms. *
8 * J_LZ_COPYRIGHT_END *********************************************************/

9
10 package org.openlaszlo.utils;
11
12 /**
13  * Thread safe counter object.
14  */

15 public class ThreadSafeCounter {
16     int mCount = 0;
17     synchronized public void increment() {
18         ++mCount;
19     }
20     synchronized public void decrement() {
21         --mCount;
22     }
23     synchronized public void decrement(int n) {
24         mCount-=n;
25     }
26     synchronized public int getCount() {
27         return mCount;
28     }
29 }
30
Popular Tags