Loading

摘要: ##实现Callable接口 实现Callable接口,需要返回值类型 重写call方法,需要抛出异常 创建目标对象 创建执行服务:ExecutorService ser = Executors.newFixedThreadPool(1) 提交执行Future result1 = ser.submi 阅读全文
posted @ 2022-02-13 23:56 Cn_FallTime 阅读(132) 评论(0) 推荐(0) 编辑
摘要: ##龟兔赛跑问题 public class TestThread5 implements Runnable{ private static String winner;//注意final是静态常量不可修改 private static int num=0; @Override public void 阅读全文
posted @ 2022-02-13 23:26 Cn_FallTime 阅读(50) 评论(0) 推荐(0) 编辑
摘要: ##多线程并发问题 //多个线程同时操作同一个对象 //买火车票的例子 public class TestThread4 implements Runnable{ //票数 private int tickerNums =10; @Override public void run() { while 阅读全文
posted @ 2022-02-13 22:49 Cn_FallTime 阅读(22) 评论(0) 推荐(0) 编辑
摘要: ##使用Thread实现多线程 public class MyThread extends Thread { private int ticket = 5; @Override public void run() { while (true) { System.out.println("Thread 阅读全文
posted @ 2022-02-13 00:51 Cn_FallTime 阅读(26) 评论(0) 推荐(0) 编辑