Beispiel #1
0
 public void run() {
   Timer timer = new Timer();
   timer.startTimer();
   while (t2.v < endTime) {
     if (t2.v % 2 == parameter) {
       t2.v += 1;
     }
   }
   timer.endTimer();
   timer.printMeasuredTime("time for volatile: ");
 }
Beispiel #2
0
 public void run() {
   Timer timer = new Timer();
   timer.startTimer();
   while (t2.nv < endTime) {
     lock.getLock(id);
     if (t2.nv % 2 == parameter) {
       t2.nv += 1;
     }
     lock.unLock(id);
   }
   timer.endTimer();
   timer.printMeasuredTime("time for volatile lock: ");
 }
Beispiel #3
0
    public void run() {
      Timer timer = new Timer();
      timer.startTimer();
      int counter = 0;
      while (t2.nv < endTime) {
        synchronized (t2) {
          // satawal needs for this code much longer, than for the code above (loses factor 10)
          if (t2.nv < endTime) {
            counter++;
            t2.nv += 1;
          }

          // if (t2.nv % 2 == parameter) {
          // t2.nv += 1;
          // }

        }
      }
      timer.endTimer();
      timer.printMeasuredTime("time for synchronied: ");
      System.out.println(Thread.currentThread().getId() + ":" + counter);
    }