01: /*
02:
03: Copyright 2004, Martian Software, Inc.
04:
05: Licensed under the Apache License, Version 2.0 (the "License");
06: you may not use this file except in compliance with the License.
07: You may obtain a copy of the License at
08:
09: 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 {
30:
31: private String name = null;
32:
33: public ThreadTest(String 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 {
41: Thread.sleep(100);
42: } catch (Throwable t) {
43: }
44: }
45: }
46:
47: public static void main(String[] args) {
48: for (int i = 0; i < 3; ++i) {
49: Thread t = new Thread(new ThreadTest("T" + i));
50: t.start();
51: System.out.println("Started number " + i);
52: }
53:
54: try {
55: Thread.sleep(2000);
56: } catch (Throwable t) {
57: }
58: System.out.println("Done.");
59: }
60: }
|