home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-04-20 | 574 b | 31 lines |
- class Ex1204d {
- public static void main(String[] args) {
- MyThread t1 = new MyThread(1);
- MyThread t2 = new MyThread(2);
-
- t1.other = t2;
- t2.other = t1;
-
- t1.start();
- t2.start();
- }
- }
-
- class MyThread extends Thread {
- int id;
- MyThread other;
- MyThread(int id) {
- this.id = id;
- }
-
- public void run() {
- if (id == 1)
- other.suspend();
- for (int i = 0; i < 100; i++) {
- System.out.println("My id is " + id);
- }
- if (id == 1)
- other.resume();
- }
- }
-