KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > martiansoftware > nailgun > examples > ThreadTest


1 /*
2
3 Copyright 2004, Martian Software, Inc.
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16
17 */

18
19 package com.martiansoftware.nailgun.examples;
20
21 /**
22  * A very silly test to verify that the System.in/out/err overrides are
23  * inherited by child threads. A bunch of numbers and thread ids are displayed
24  * to the client's stdout. The important thing is that all threads launched
25  * by the nail are writing to the same client.
26  *
27  * @author <a HREF="http://www.martiansoftware.com/contact.html">Marty Lamb</a>
28  */

29 public class ThreadTest implements Runnable JavaDoc {
30
31     private String JavaDoc name = null;
32     
33     public ThreadTest(String JavaDoc name) {
34         this.name = name;
35     }
36     
37     public void run() {
38         for (int i = 0; i < 10; ++i) {
39             System.out.println(name + ": " + i);
40             try {Thread.sleep(100);} catch (Throwable JavaDoc t){}
41         }
42     }
43     
44     public static void main(String JavaDoc[] args) {
45         for (int i = 0; i < 3; ++i) {
46             Thread JavaDoc t = new Thread JavaDoc(new ThreadTest("T" + i));
47             t.start();
48             System.out.println("Started number " + i);
49         }
50         
51         try {Thread.sleep(2000);} catch (Throwable JavaDoc t) {}
52         System.out.println("Done.");
53     }
54 }
55
Popular Tags