21 lines
541 B
Java
Raw Normal View History

2016-12-21 11:06:49 -08:00
// concurrent/NapTask.java
2016-12-30 17:23:13 -08:00
// (c)2017 MindView LLC: see Copyright.txt
2016-07-05 14:46:09 -06: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.
2016-12-21 11:06:49 -08:00
import onjava.Nap;
2016-07-05 14:46:09 -06:00
2016-12-21 11:06:49 -08:00
public class NapTask implements Runnable {
2016-07-05 14:46:09 -06:00
final int id;
2016-12-21 11:06:49 -08:00
public NapTask(int id) { this.id = id; }
2016-07-05 14:46:09 -06:00
@Override
public void run() {
2016-12-21 11:06:49 -08:00
new Nap(100); // Milliseconds
2016-07-05 14:46:09 -06:00
System.out.println(this + " " +
Thread.currentThread().getName());
}
@Override
public String toString() {
2016-12-21 11:06:49 -08:00
return "NapTask[" + id + "]";
2016-07-05 14:46:09 -06:00
}
}