Advertisement
Ankhwatcher

SynchronizedCounter

Aug 4th, 2011
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.46 KB | None | 0 0
  1. package org.gtug.trafficcam;
  2.  
  3. public class SynchronisedCounter
  4. {
  5.         private int c = 0;
  6.         public synchronized void restore()
  7.         {
  8.             c = 0;
  9.         }
  10.        
  11.         public synchronized void setTo(int setTo)
  12.         {
  13.             c = setTo;
  14.         }
  15.         public synchronized void increment()
  16.         {
  17.             c++;
  18.         }
  19.  
  20.         public synchronized void decrement()
  21.         {
  22.             c--;
  23.         }
  24.  
  25.         public synchronized int value() {
  26.             return c;
  27.         }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement