-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathWorker.java
More file actions
37 lines (33 loc) · 818 Bytes
/
Worker.java
File metadata and controls
37 lines (33 loc) · 818 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
26
27
28
29
30
31
32
33
34
35
36
37
package threadpool;
/**
* Worker implements {@link Runnable} and thus can be executed by {@link
* java.util.concurrent.ExecutorService}.
* @author nemo
*/
public class Worker implements Runnable {
private final Task task;
/**
* @param task task to execute by worker
*/
public Worker(final Task task) {
this.task = task;
}
/**
* run worker
*/
@Override
public void run() {
System.out.println(
String.format(
"(" + this.toString() + "): " + "%s processing %s",
Thread.currentThread().getName(),
task.toString()
)
);
try {
Thread.sleep(task.getTimeMs());
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}