Run method discussion

By: Nicholas Duchon, Feb 29, 2016

See the Discussion following the code


  1 public void run () {
 2   long time = System.currentTimeMillis();
 3   long startTime = time;
 4   long stopTime = time + 1000 * jobTime;
 5   double duration = stopTime - time;
 6
 7   synchronized (worker.party) { // party since looking forward to P4 requirements
 8     while (worker.busyFlag) {
 9       showStatus (Status.WAITING);
10       try {
11         worker.party.wait();
12       }
13       catch (InterruptedException e) {
14       } // end try/catch block
15     } // end while waiting for worker to be free
16     worker.busyFlag = true;
17   } // end sychronized on worker
18
19  
while (time < stopTime && noKillFlag) {
20     try {
21       Thread.sleep (100);
22     } catch (InterruptedException e) {}
23     if (goFlag) {
24       showStatus (Status.RUNNING);
25       time += 100;
26       pm.setValue ((int)(((time - startTime) / duration) * 100));
27     } else {
28       showStatus (Status.SUSPENDED);
29     } // end if stepping
30   } // end runninig
31
32  
pm.setValue (100);
33   showStatus (Status.DONE);
34   synchronized (worker.party) {
35     worker.busyFlag = false;
36     worker.party.notifyAll ();
37   }
38
39
} // end method run - implements runnable


Discussion: