KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > utils > ThreadSafeCounter


1 package com.daffodilwoods.daffodildb.utils;
2
3 /**
4  * <p>Title:ThreadSafeCounter </p>
5  * <p>Description: This class is wrapper around int type to perform unary incrmental/decrement operation around
6  * in thread safe manner . </p>
7  * <p>Company: Daffodil Software Limited</p>
8  * @author Manoj Kr. Sheoran
9  * @version 1.0
10  */

11 public class ThreadSafeCounter {
12     private int count = 0;
13     public ThreadSafeCounter(int count) {
14         this.count = count;
15     }
16     public synchronized void inreaseCount() {
17         count++;
18     }
19     public synchronized void decreaseCount() {
20         count--;
21     }
22     public synchronized int getCount() {
23         return count;
24     }
25
26 }
27
Popular Tags