home *** CD-ROM | disk | FTP | other *** search
/ Java Certification Exam Guide / McGrawwHill-JavaCertificationExamGuide.iso / pc / Web Links and Code / ans / chap12 / exer1204 / Ex1204b.java < prev    next >
Encoding:
Java Source  |  1997-04-20  |  664 b   |  32 lines

  1. class Ex1204b {
  2.    public static void main(String[] args) {
  3.       MyThread t1 = new MyThread(1);
  4.       MyThread t2 = new MyThread(2);
  5.  
  6.       t1.setPriority(Thread.MAX_PRIORITY);
  7.       t2.setPriority(Thread.MIN_PRIORITY);
  8.  
  9.       t1.start();
  10.       t2.start();
  11.    }
  12. }
  13.  
  14. class MyThread extends Thread {
  15.    int id;
  16.    MyThread(int id) {
  17.       this.id = id;
  18.    }
  19.  
  20.    public void run() {
  21.       for (int i = 0; i < 100; i++) {
  22.          if (id == 1 && i == 50) {
  23.             try {
  24.                sleep(1000);
  25.             } catch (InterruptedException x) {
  26.             }
  27.          }
  28.          System.out.println("My id is " + id);
  29.       }
  30.    }
  31. }
  32.