forked from PacktPublishing/Java-Coding-Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrinter.java
More file actions
25 lines (20 loc) · 667 Bytes
/
Copy pathPrinter.java
File metadata and controls
25 lines (20 loc) · 667 Bytes
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
package modern.challenge;
import java.nio.file.Path;
import java.util.Random;
public class Printer implements Runnable {
private final Path filePath;
public Printer(Path filePath) {
this.filePath = filePath;
}
@Override
public void run() {
try {
//sleep a random number of seconds for simulating dispaching and printing
Thread.sleep(10000 + new Random().nextInt(30000));
System.out.println("Printing: " + filePath);
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
System.err.println("Exception: " + ex);
}
}
}