Ticket #231: test.java

File test.java, 1.7 KB (added by dmik, 11 years ago)
Line 
1class TestThread extends Thread
2{
3 private boolean doExit;
4
5 TestThread(boolean doExit) { this.doExit = doExit; }
6
7 public void run()
8 {
9 System.out.println("Started thread " + Thread.currentThread() + "," + Thread.currentThread().getId() + ": doExit=" + doExit);
10
11 try
12 {
13 if (doExit)
14 {
15 System.out.println("EXITING");
16 System.exit(1);
17 //Runtime.getRuntime().halt(1);
18 }
19 else
20 {
21 int n = 1234;
22 for (int i = 0; i < 2000000000; ++i)
23 {
24 if (n == 0) n = 1234;
25 n = n * (n+1) * (n+2);
26 }
27 System.out.println("RESULT " + n);
28 }
29 }
30 catch (Exception e)
31 {
32 e.printStackTrace();
33 }
34
35 System.out.println("Finished thread " + Thread.currentThread() + "," + Thread.currentThread().getId());
36 }
37}
38
39public class test
40{
41 public static void main(String args[])
42 {
43 System.out.println("Started main thread " + Thread.currentThread() + "," + Thread.currentThread().getId());
44
45 TestThread t1 = new TestThread(false);
46 t1.start();
47
48 TestThread t2 = new TestThread(true);
49 t2.start();
50
51 //System.out.println("EXITING main");
52 //System.exit(1);
53
54 try
55 {
56 t1.join();
57 t2.join();
58 }
59 catch (Exception e)
60 {
61 e.printStackTrace();
62 }
63
64
65 System.out.println("Finished main thread " + Thread.currentThread() + "," + Thread.currentThread().getId());
66 }
67}