FileDocCategorySizeDatePackage
Counter1.javaAPI DocExample566Sun Feb 27 14:34:06 GMT 2000tuning.threads

Counter1.java

package tuning.threads;

public class Counter1
{
  //For simplicity make just 10 counters
  static long[] vec = new long[10]; 

  public static void initialize(int key)
  {
    vec[key] = 0;
  }

  //And also make the just make key the index into the array
  public static void addAmount(int key, long amount)
  {
    //This is not atomically synchronized since we do an array
    //access together with an update, which are two operations.
    vec[key] += amount;
  }

  public static long getAmount(int key)
  {
    return vec[key];
  }
}