2016-12-21 11:06:49 -08:00
|
|
|
// onjava/Nap.java
|
2020-10-07 13:35:40 -06:00
|
|
|
// (c)2020 MindView LLC: see Copyright.txt
|
2015-11-15 15:51:35 -08:00
|
|
|
// We make no guarantees that this code is fit for any purpose.
|
2016-09-23 13:23:35 -06:00
|
|
|
// Visit http://OnJava8.com for more book information.
|
2015-11-11 20:20:04 -08:00
|
|
|
package onjava;
|
2015-06-15 17:47:35 -07:00
|
|
|
import java.util.concurrent.*;
|
|
|
|
|
2016-12-21 11:06:49 -08:00
|
|
|
public class Nap {
|
2017-01-23 08:19:11 -08:00
|
|
|
public Nap(double t) { // Seconds
|
2015-06-15 17:47:35 -07:00
|
|
|
try {
|
2017-01-23 08:19:11 -08:00
|
|
|
TimeUnit.MILLISECONDS.sleep((int)(1000 * t));
|
2017-01-22 16:48:11 -08:00
|
|
|
} catch(InterruptedException e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
2017-01-23 08:19:11 -08:00
|
|
|
public Nap(double t, String msg) {
|
|
|
|
this(t);
|
2017-01-22 16:48:11 -08:00
|
|
|
System.out.println(msg);
|
|
|
|
}
|
2015-09-07 11:44:36 -06:00
|
|
|
}
|