aboutsummaryrefslogtreecommitdiffstats
path: root/tests/debugger/AJDBThreads.java
blob: c3cc5e2e60905557977ecce26abdbc2becaa3cd2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//package debugger;

public class AJDBThreads {
    public static void main(String[] args) {
        new ThreadForker().go();
    }
    public static String currentThread = "none";
}

class ThreadForker {
    public void go() {
        fork(1000);
        fork(500);
        fork(200);
        fork(100);
    }

    void fork(long sleep) {
        new NamedThread(sleep).start();
    }
}

class NamedThread implements Runnable {
    private long sleep;
    private String name;
    private Thread thread;
    private int num = 0;

    public NamedThread(long sleep) {
        this.sleep = sleep;
    }

    public void start() {
        if (thread == null) {
            thread = new Thread(this);
            name = thread.getName();
            thread.start();
        }
    }
    
    public void run() {
        while (true) {
            AJDBThreads.currentThread = name;
            System.out.println("\n********** " + AJDBThreads.currentThread + ":" + (num++) + "\n");
            try {
                Thread.sleep(sleep);
            } catch (Exception e) {
            }                
        }
    }
}