2021年3月8日
摘要: 线程锁lock package com.peanutist.day10;​import com.sun.org.apache.bcel.internal.generic.NEW;​import java.util.concurrent.locks.Lock;import java.util.conc 阅读全文
posted @ 2021-03-08 23:48 要给小八赚罐头钱 阅读(81) 评论(0) 推荐(0)
摘要: 线程池ExecutorService ExecutorService才是真正的线程池接口 import java.util.concurrent.ExecutorService;import java.util.concurrent.Executors;​public class TestExecu 阅读全文
posted @ 2021-03-08 23:25 要给小八赚罐头钱 阅读(35) 评论(0) 推荐(0)
摘要: 保证线程安全-信号灯法 设立flag,一个线程flag=true时跑,另一个线程wait(),跑完了告诉另外一个线程可以跑了notifyAll() public class TestThreadWait2 { public static void main(String[] args) { TV t 阅读全文
posted @ 2021-03-08 23:12 要给小八赚罐头钱 阅读(40) 评论(0) 推荐(0)
摘要: 管程法 this.wait();让该线程等待 this.notifyAll();让另外线程开始 public class TestThreadWait { public static void main(String[] args) { SynContainer synContainer = new 阅读全文
posted @ 2021-03-08 22:21 要给小八赚罐头钱 阅读(128) 评论(0) 推荐(0)
摘要: 线程同步方法synchronized synchronized修饰需要控制资源的方法。 public class TestSynchronized { public static void main(String[] args) { BuyTicket buyTicket = new BuyTick 阅读全文
posted @ 2021-03-08 20:52 要给小八赚罐头钱 阅读(31) 评论(0) 推荐(0)