File: output.java

package info (click to toggle)
jswat2 2.37-1
  • links: PTS
  • area: contrib
  • in suites: etch, etch-m68k
  • size: 7,092 kB
  • ctags: 5,592
  • sloc: java: 43,576; xml: 1,086; sh: 66; makefile: 57
file content (55 lines) | stat: -rw-r--r-- 1,982 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// An output-only test for JSwat.
// $Id: output.java 662 2002-11-02 07:25:59Z nfiedler $

import java.io.*;

public class output {

    protected static void printStuff(int sleepLen, int numLoops) {
        try {
            for (int i = 0; i < numLoops; i++) {
                System.out.println("out 1");
                Thread.sleep((long) (Math.random() * sleepLen));
                System.err.println("err 1");
                Thread.sleep((long) (Math.random() * sleepLen));
                System.out.println("out 2");
                Thread.sleep((long) (Math.random() * sleepLen));
                System.err.println("err 2");
                Thread.sleep((long) (Math.random() * sleepLen));
                System.out.println("out 3");
                Thread.sleep((long) (Math.random() * sleepLen));
                System.err.println("err 3");
                Thread.sleep((long) (Math.random() * sleepLen));
                System.out.println("out 4");
                Thread.sleep((long) (Math.random() * sleepLen));
                System.err.println("err 4");
            }
        } catch (InterruptedException ie) {
            // yeah, like that'll ever happen
            ie.printStackTrace();
        }
    }

    public static void main(String[] args) {

        int sleepLen = 2000;
        int numLoops = 10;
        if (args.length > 0) {
            try {
                sleepLen = Integer.parseInt(args[0]);
            } catch (NumberFormatException nfe) {
                System.err.println("First argument must be an integer!");
                System.exit(1);
            }
            if (args.length > 1) {
                try {
                    numLoops = Integer.parseInt(args[1]);
                } catch (NumberFormatException nfe) {
                    System.err.println("Second argument must be an integer!");
                    System.exit(1);
                }
            }
        }
        printStuff(sleepLen, numLoops);
    }
}