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