MyRunnable.java 821 字节
Newer Older
K
Kou Shuang 已提交
1 2
package threadPoolExecutor;

K
Kou Shuang 已提交
3 4 5 6 7 8
import java.util.Date;

/**
 * 这是一个简单的Runnable类,需要大约5秒钟来执行其任务。
 * @author shuang.kou
 */
K
Kou Shuang 已提交
9
public class MyRunnable implements Runnable {
K
Kou Shuang 已提交
10 11 12

    private String command;

K
Kou Shuang 已提交
13
    public MyRunnable(String s) {
K
Kou Shuang 已提交
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
        this.command = s;
    }

    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName() + " Start. Time = " + new Date());
        processCommand();
        System.out.println(Thread.currentThread().getName() + " End. Time = " + new Date());
    }

    private void processCommand() {
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    @Override
    public String toString() {
        return this.command;
    }
}