home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Documents / JAVA Programming / examples / 11 / HiLoPri.java < prev    next >
Encoding:
Java Source  |  2000-09-08  |  713 b   |  34 lines

  1. class Clicker implements Runnable { 
  2. 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. public void run() {
  9. while (running) { 
  10. click++;       
  11. } }
  12. public void stop() {
  13. running = false;  }
  14. public void start() {
  15. t.start();
  16. } }
  17. class HiLoPri {
  18. public static void main(String args[]) {
  19. Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
  20. Clicker hi = new Clicker(Thread.NORM_PRIORITY + 2);
  21. Clicker lo = new Clicker(Thread.NORM_PRIORITY - 2);
  22. lo.start();
  23. hi.start();
  24. try {
  25. Thread.sleep(-10000);
  26. }
  27. catch (Exception e) {
  28. }
  29. lo.stop();
  30. hi.stop();
  31. System.out.println(lo.click + " vs. " + hi.click); 
  32. } }
  33.