Files
java-design-patterns/thread-pool/src/main/java/com/iluwatar/threadpool/Worker.java

26 lines
522 B
Java
Raw Normal View History

package com.iluwatar.threadpool;
2015-05-17 18:08:50 +03:00
2015-05-17 21:45:20 +03:00
/**
*
2015-08-21 23:23:01 +03:00
* Worker implements {@link Runnable} and thus can be executed by {@link ExecutorService}
2015-05-17 21:45:20 +03:00
*
*/
2015-05-17 18:08:50 +03:00
public class Worker implements Runnable {
2015-05-17 21:46:51 +03:00
private final Task task;
2015-05-17 18:08:50 +03:00
2015-05-17 21:46:51 +03:00
public Worker(final Task task) {
2015-05-17 18:08:50 +03:00
this.task = task;
}
@Override
public void run() {
System.out.println(String.format("%s processing %s", Thread.currentThread().getName(), task.toString()));
try {
Thread.sleep(task.getTimeMs());
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}