summaryrefslogtreecommitdiffstats
path: root/Master/Reference Architectures and Patterns/hjp5/examples/Listing1605.java
blob: 2ddb862ed54c0ea07e690e91362d74e57050f47f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* Listing1605.java */

public class Listing1605
{
  public static void main(String[] args)
  {
    long t1, t2;
    int  actres, sumres = 0, i = 0;
    while (true) {
      ++i;
      t1 = System.currentTimeMillis();
      while (true) {
        t2 = System.currentTimeMillis();
        if (t2 != t1) {
          actres = (int)(t2 - t1);
          break;
        }
      }
      sumres += actres;
      System.out.print("it="+i+", ");
      System.out.print("actres="+actres+" msec., ");
      System.out.print("avgres="+(sumres/i)+" msec.");
      System.out.println("");
      try {
        Thread.sleep(500);
      } catch (InterruptedException e) {
        //nichts
      }
    }
  }
}