java线程的一段代码
程序员文章站
2022-07-15 15:17:52
...
public static void main(String[] args) throws Exception {
ExecutorService threadpool = Executors.newFixedThreadPool(1);
Callable r = new Callable() {
@Override
public String call() {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
return "11111";
}
};
FutureTask<String> f = new FutureTask<>(r);
new Thread(f).start();
System.out.println(f.get());
System.out.println("end");
Runnable r = new Runnable() {
@Override
public void run() {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("runnable");
}
};
Thread t = new Thread(r);
t.start();
LockSupport.unpark(t);
System.out.println("hhh");
}
上一篇: Vue自已写的日历插件