1   public class Clicker implements Runnable {

2     private int click = 0;

3     private Thread t;

4     private boolean running = true;

5     public Clicker(int p) {

6       t = new Thread(this);

7       t.setPriority(p);

8     }

9     public int getClick(){

10      return click;

11    }

12    public void run() {

13      while (running) {

14        click++;

15      }

16    }

17    public void stopThread() {

18      running = false;

19    }

20    public void startThread() {

21      t.start();

22    }

23  }

24  public class ThreadRace {

25    public static void main(String args[]) {

26      Thread.currentThread().setPriority(Thread.MAX_PRIORITY);

27      Clicker hi = new Clicker(Thread.NORM_PRIORITY + 2);

28      Clicker lo = new Clicker(Thread.NORM_PRIORITY - 2);

29      lo.startThread();

30      hi.startThread();

31      try {

32        Thread.sleep(10000);

33      }

34      catch (Exception e){}

35      lo.stopThread();

36      hi.stopThread();

37      System.out.println(lo.getClick()+" vs. "+hi.getClick());

38    }

39  }