jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 1 | public class Main { |
| 2 | static public void main(String[] args) throws Exception { |
| 3 | int millis = 1000; |
| 4 | |
Mathieu Chartier | 031768a | 2015-08-27 10:25:02 -0700 | [diff] [blame] | 5 | if (args.length > 1) { |
| 6 | millis = Integer.parseInt(args[1]); |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 7 | } |
| 8 | |
| 9 | System.out.println("Sleeping " + millis + " msec..."); |
| 10 | |
| 11 | long start = System.currentTimeMillis(); |
| 12 | Thread.sleep(millis); |
| 13 | long elapsed = System.currentTimeMillis() - start; |
| 14 | long offBy = Math.abs(elapsed - millis); |
| 15 | |
| 16 | System.out.println("Done sleeping"); |
| 17 | |
| 18 | if (offBy > 250) { |
| 19 | System.out.println("Actually slept about " + elapsed + " msec..."); |
| 20 | } |
| 21 | } |
| 22 | } |