随笔分类 -  线程

摘要:1.New 一个线程 ;Runnable是用了start()线程可运行,启动;用了synchronized锁会进入BLOCKED状态,需要获得monitor();等候WAITING状态是上面的方法等候,下面的方法唤醒;计时等待TIMED WAITING是有参的方法类似于WAITING,带参是等候的时 阅读全文
posted @ 2021-11-10 09:42 创嗨 阅读(22) 评论(0) 推荐(0) 编辑
摘要:1.使用stop()方法错误的停止线程,会导致强行停止,而不给考虑的机会,interrupt不会直接停止 import lombok.extern.slf4j.Slf4j;@Slf4j/** * 使用stop()方法错误的停止线程,会导致强行停止,而不给考虑的机会,interrupt不会直接停止 * 阅读全文
posted @ 2021-11-05 09:24 创嗨 阅读(50) 评论(0) 推荐(0) 编辑
摘要:1.使用interrupt关闭线程 /** * 使用interrupt关闭线程,注意不可强制,而是要判断true如果当前线程已被中断; false除此以外。!Thread.currentThread().isInterrupted() */public class RightWayStopThrea 阅读全文
posted @ 2021-11-02 17:57 创嗨 阅读(29) 评论(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 创嗨 阅读(25) 评论(0) 推荐(0) 编辑
摘要:都是在之前创建线程的基础上创建的线程 1. 利用线程池创建线程 1.哪个方法需要线程,比如Task里面的方法需要使用线程那么实现Runnable 2.用线程池的.submit去调用这个线程 public class ThreadPool5 { public static void main(Stri 阅读全文
posted @ 2021-11-02 09:38 创嗨 阅读(56) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示