摘要:
正确的停止线程 使用interrupu来通知,而不是强制 interrupu仅仅是通知,线程本身具有决定权是否终止,原因:线程本身了解自己的运行状态,即:自己的任务是不是已经完成了,所以把决定权交给线程自己 public class RightWayStop implements Runnable 阅读全文
posted @ 2021-12-22 23:54
Zhbeii
阅读(30)
评论(0)
推荐(0)
摘要:
start()与run()的比较 public class StartAndRunMethod { public static void main(String[] args) { Runnable runnable = () ->{ System.out.println(Thread.curren 阅读全文
posted @ 2021-12-22 23:33
Zhbeii
阅读(31)
评论(0)
推荐(0)
摘要:
public class wrongways { public static void main(String[] args) { ExecutorService executorService = Executors.newCachedThreadPool(); for(int i = 0;i < 阅读全文
posted @ 2021-12-22 21:49
Zhbeii
阅读(67)
评论(0)
推荐(0)
摘要:
实现Runnable接口 public class RunnableStyle implements Runnable { public static void main(String[] args) { Thread thread = new Thread(new RunnableStyle()) 阅读全文
posted @ 2021-12-22 21:34
Zhbeii
阅读(71)
评论(0)
推荐(0)