package com.itheima.threaddemo7;
import java.util.concurrent.FutureTask;
public class Demo {
public static void main(String[] args) {
MyCallable mc=new MyCallable();
FutureTask<String> tf=new FutureTask<>(mc);
Thread t1=new Thread(tf);
t1.setName("飞机");
t1.setPriority(10);
System.out.println(t1.getPriority());
t1.start();
MyCallable mc2=new MyCallable();
FutureTask<String> tf2=new FutureTask<>(mc2);
Thread t2=new Thread(tf2);
t2.setName("坦克");
t2.setPriority(1);
System.out.println(t2.getPriority());
t2.start();
}
}
package com.itheima.threaddemo7;
import java.util.concurrent.Callable;
public class MyCallable implements Callable<String> {
@Override
public String call() throws Exception {
for (int i = 0; i < 100; i++) {
System.out.println(Thread.currentThread().getName()+"---"+i);
}
return "线程执行完毕了";
}
}
|