• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2006 The Android Open Source Project
2 
3 /**
4  * Test some basic thread stuff.
5  */
6 public class Main {
main(String[] args)7     public static void main(String[] args) {
8         for (int i = 0; i < 512; i++) {
9             MyThread myThread = new MyThread();
10             myThread.start();
11             try {
12                 Thread.sleep(1);
13             } catch (InterruptedException ie) {
14                 ie.printStackTrace();
15             }
16         }
17 
18         go();
19         System.out.println("thread test done");
20     }
21 
go()22     public static void go() {
23         Thread t = new Thread(null, new ThreadTestSub(), "Thready", 7168);
24 
25         t.setDaemon(false);
26 
27         System.out.print("Starting thread '" + t.getName() + "'\n");
28         t.start();
29 
30         try {
31             t.join();
32         } catch (InterruptedException ex) {
33             ex.printStackTrace();
34         }
35 
36         System.out.print("Thread starter returning\n");
37     }
38 
39     /*
40      * Simple thread capacity test.
41      */
42     static class MyThread extends Thread {
43         private static int mCount = 0;
run()44         public void run() {
45             System.out.println("running " + (mCount++));
46         }
47     }
48 }
49 
50 class ThreadTestSub implements Runnable {
run()51     public void run() {
52         System.out.print("@ Thread running\n");
53 
54         try {
55             Thread.currentThread().setDaemon(true);
56             System.out.print("@ FAILED: setDaemon() succeeded\n");
57         } catch (IllegalThreadStateException itse) {
58             System.out.print("@ Got expected setDaemon exception\n");
59         }
60 
61         //if (true)
62         //    throw new NullPointerException();
63         try {
64             Thread.sleep(2000);
65         }
66         catch (InterruptedException ie) {
67             System.out.print("@ Interrupted!\n");
68         }
69         finally {
70             System.out.print("@ Thread bailing\n");
71         }
72     }
73 }
74