随笔分类 -  多线程

摘要: 阅读全文
posted @ 2022-07-14 16:14 小布丁dd 阅读(16) 评论(0) 推荐(0) 编辑
摘要:public class TestJoin implements Runnable{ public void run(){ for(int i=0;i<100;i++){ System.out.println("线程vip来了");} } } public static void main(Stri 阅读全文
posted @ 2022-07-14 15:57 小布丁dd 阅读(17) 评论(0) 推荐(0) 编辑
摘要:sleep 存在异常InterruptedException 每一个对象都有一把锁,sleep不会释放锁。 (线程同步) 1.模拟延时 try{ Thread.sleep(millis:100); }catch(InterruptedException e){ e.printStackTrace() 阅读全文
posted @ 2022-06-26 18:36 小布丁dd 阅读(13) 评论(0) 推荐(0) 编辑
摘要:1.建议线程自己正常停止 > 利用次数,不建议死循环。 2.设置标志位 > 3.不用stop destory 方法。 public class TestStop implements Runnable{ //1. 设置标志位 prviate boolean flag= true; public vo 阅读全文
posted @ 2022-06-26 18:12 小布丁dd 阅读(27) 评论(0) 推荐(0) 编辑
摘要:推导: 实现类-> 静态内部类-> 局部内部类 -> 匿名内部类 -> Lamda表达式 public class TestLambda1 { //3.静态内部类 static class Like2 implements ILike{ @Override public void lambda() 阅读全文
posted @ 2022-06-25 16:05 小布丁dd 阅读(25) 评论(0) 推荐(0) 编辑
摘要:静态代理模式分析 抽象角色 : 一般使用接口来实现 真实角色 : 被代理的角色 代理角色 : 代理真实角色 ; 代理真实角色后 , 一般会做一些附属的操作 .里边含有若干方法。 客户 : 使用代理角色来进行一些操作 .把真实角色传到代理角色里。 真实角色 和 代理角色 实现同一接口 Thread类就 阅读全文
posted @ 2022-06-21 11:05 小布丁dd 阅读(39) 评论(0) 推荐(0) 编辑
摘要:1.实现callable接口, 需要返回值类型 2.重写 call方法, 需要抛出异常 3.创建目标对象 4.创建执行服务:ExecutorService ser = Executors.newFlxedThreadPool(1); 5 提交执行 Future<Boolean> result1 = 阅读全文
posted @ 2022-06-21 10:48 小布丁dd 阅读(56) 评论(0) 推荐(0) 编辑
摘要:创建线程方式2: 实现runnable 接口, 重新run方法,丢入runnable接口实现类,调用start方法 1 定义 MyRunnable 类 实现Runnable 接口 2实现run方法,编写线程执行体 3创建线程对象,调用start方法启动线程 1 public static void 阅读全文
posted @ 2022-05-05 21:18 小布丁dd 阅读(78) 评论(0) 推荐(0) 编辑
摘要:准备工作: Bing 搜索 commons-io 并下载。 https://commons.apache.org/proper/commons-io/download_io.cgi 把 commons-io 文件夹中的 commons-io-2.8.0.jar 添加到项目中。 复制代码 packag 阅读全文
posted @ 2022-05-04 16:48 小布丁dd 阅读(36) 评论(0) 推荐(0) 编辑
摘要:调用线程方式一: 调用Thread 类 ,重新run方法,调用start 开启线程 public static void main(String [] args){ TestThread test1 = new TestThread(); //创建线程对象 test1.start(); //调用st 阅读全文
posted @ 2022-05-04 16:25 小布丁dd 阅读(88) 评论(0) 推荐(0) 编辑

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