Yurttas/PL/OOL/Java/F/07/02/R00.java
Jump to navigation
Jump to search
1/**
2 * Copyright(C) 1998
3 * All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc..
4 *
5 * Permission to use, copy, modify, and distribute this
6 * software and its documentation for EDUCATIONAL purposes
7 * and without fee is hereby granted provided that this
8 * copyright notice appears in all copies.
9 *
10 * @date : January 1, 1998.
11 * @author : Salih Yurttas.
12 */
13
14
15public class R00 implements Runnable {
16
17 public static void main(String[] args) {
18 int delay1,
19 delay2;
20
21 switch(args.length) {
22 case 2 : delay1 = Integer.parseInt(args[0]);
23 delay2 = Integer.parseInt(args[1]);
24 break;
25 default: delay1 = 10;
26 delay2 = 60;
27 }
28
29 R00 runnable1 = new R00("Thread 1",
30 delay1);
31 R00 runnable2 = new R00(" Thread 2",
32 delay2);
33
34 Thread thread1 = new Thread(runnable1);
35 Thread thread2 = new Thread(runnable2);
36
37 thread1.start();
38 thread2.start();
39 }
40
41 private static final int N=16;
42
43 private String label;
44 private int delay;
45
46 public R00(final String id,
47 final int d) {
48 label = id;
49 delay = d;
50 }
51
52 public void run() {
53 try {
54 for(int i=0; i<N; i++) {
55 System.out.println(label + ": " + i);
56 Thread.sleep(delay);
57 }
58 }
59 catch(InterruptedException iE) {
60 return;
61 }
62 }
63
64}