摘要: 1.使用interrupt关闭线程 /** * 使用interrupt关闭线程,注意不可强制,而是要判断true如果当前线程已被中断; false除此以外。!Thread.currentThread().isInterrupted() */public class RightWayStopThrea 阅读全文
posted @ 2021-11-02 17:57 创嗨 阅读(41) 评论(0) 推荐(0)
摘要: /** * run and start 区别 */public class StartAndRunMethod { public static void main(String[] args) { Runnable runnable = () ->{ System.out.println(Threa 阅读全文
posted @ 2021-11-02 13:13 创嗨 阅读(34) 评论(0) 推荐(0)
摘要: 都是在之前创建线程的基础上创建的线程 1. 利用线程池创建线程 1.哪个方法需要线程,比如Task里面的方法需要使用线程那么实现Runnable 2.用线程池的.submit去调用这个线程 public class ThreadPool5 { public static void main(Stri 阅读全文
posted @ 2021-11-02 09:38 创嗨 阅读(61) 评论(0) 推荐(0)