6、JUC:傳統的生產者消費者問題,防止虛假喚醒問題
學習過程觀看視訊:[狂神說Java]
https://www.bilibili.com/video/BV1B7411L7tE?p=2
歡迎大家支援噢,很良心的老師了!
執行緒通訊案例:
package com.zjl;
/**
* Created by zjl
* 2020/11/20
**/
/*
* 1、執行緒之間的通訊問題:生產者和消費者問題!
* 2、執行緒交替執行,A B 操作同一個變數 num = 0
* 3、A num+1
* 4、B num-1
* */
public class Test {
public static void main(String[] args) {
Data data = new Data();
new Thread(()->{
for (int i = 0; i < 10; i++) {
try {
data.increment();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
new Thread(()->{
for (int i = 0; i < 10; i++) {
try {
data.decrement();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
}
}
//等待-----》業務-----》通知
class Data{ //數字,資源類
private int number = 0;
//+1
public synchronized void increment() throws InterruptedException {
if(number!=0){
//等待
this.wait();
}
number++;
System.out.println("我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一" + number);
this.notifyAll();
}
//-1
public synchronized void decrement() throws InterruptedException {
if(number == 0){
//等待
this.wait();
}
number--;
System.out.println("我減一完畢了--------------------------喚醒其他執行緒加一" + number);
this.notifyAll();
}
}
執行結果:
/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/bin/java "-javaagent:/Users/zhangjianlong/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/193.5662.53/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=59773:/Users/zhangjianlong/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/193.5662.53/IntelliJ IDEA.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath /Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/deploy.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/ext/cldrdata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/ext/dnsns.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/ext/jaccess.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/ext/jfxrt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/ext/localedata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/ext/nashorn.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/ext/sunec.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/ext/sunjce_provider.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/ext/sunpkcs11.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/ext/zipfs.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/javaws.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/jfxswt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/management-agent.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/plugin.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/lib/ant-javafx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/lib/dt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/lib/javafx-mx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/lib/jconsole.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/lib/packager.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/lib/sa-jdi.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/lib/tools.jar:/Users/zhangjianlong/testCode/JUC-study/target/classes:/Users/zhangjianlong/apache-maven-3.6.3/repository/org/projectlombok/lombok/1.18.8/lombok-1.18.8.jar com.zjl.Test
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一1
我減一完畢了--------------------------喚醒其他執行緒加一0
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一1
我減一完畢了--------------------------喚醒其他執行緒加一0
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一1
我減一完畢了--------------------------喚醒其他執行緒加一0
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一1
我減一完畢了--------------------------喚醒其他執行緒加一0
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一1
我減一完畢了--------------------------喚醒其他執行緒加一0
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一1
我減一完畢了--------------------------喚醒其他執行緒加一0
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一1
我減一完畢了--------------------------喚醒其他執行緒加一0
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一1
我減一完畢了--------------------------喚醒其他執行緒加一0
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一1
我減一完畢了--------------------------喚醒其他執行緒加一0
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一1
我減一完畢了--------------------------喚醒其他執行緒加一0
Process finished with exit code 0
當我們把執行緒增加到4個的時候,會出現問題:
package com.zjl;
/**
* Created by zjl
* 2020/11/20
**/
/*
* 1、執行緒之間的通訊問題:生產者和消費者問題!
* 2、執行緒交替執行,A B 操作同一個變數 num = 0
* 3、A num+1
* 4、B num-1
* */
public class Test {
public static void main(String[] args) {
Data data = new Data();
new Thread(()->{
for (int i = 0; i < 10; i++) {
try {
data.increment();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
new Thread(()->{
for (int i = 0; i < 10; i++) {
try {
data.decrement();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
new Thread(()->{
for (int i = 0; i < 10; i++) {
try {
data.increment();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
new Thread(()->{
for (int i = 0; i < 10; i++) {
try {
data.decrement();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
}
}
//等待-----》業務-----》通知
class Data{ //數字,資源類
private int number = 0;
//+1
public synchronized void increment() throws InterruptedException {
if(number!=0){
//等待
this.wait();
}
number++;
System.out.println("我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一" + number);
this.notifyAll();
}
//-1
public synchronized void decrement() throws InterruptedException {
if(number == 0){
//等待
this.wait();
}
number--;
System.out.println("我減一完畢了--------------------------喚醒其他執行緒加一" + number);
this.notifyAll();
}
}
執行結果:
/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/bin/java "-javaagent:/Users/zhangjianlong/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/193.5662.53/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=59846:/Users/zhangjianlong/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/193.5662.53/IntelliJ IDEA.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath /Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/deploy.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/ext/cldrdata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/ext/dnsns.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/ext/jaccess.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/ext/jfxrt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/ext/localedata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/ext/nashorn.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/ext/sunec.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/ext/sunjce_provider.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/ext/sunpkcs11.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/ext/zipfs.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/javaws.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/jfxswt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/management-agent.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/plugin.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/lib/ant-javafx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/lib/dt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/lib/javafx-mx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/lib/jconsole.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/lib/packager.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/lib/sa-jdi.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/lib/tools.jar:/Users/zhangjianlong/testCode/JUC-study/target/classes:/Users/zhangjianlong/apache-maven-3.6.3/repository/org/projectlombok/lombok/1.18.8/lombok-1.18.8.jar com.zjl.Test
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一1
我減一完畢了--------------------------喚醒其他執行緒加一0
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一1
我減一完畢了--------------------------喚醒其他執行緒加一0
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一1
我減一完畢了--------------------------喚醒其他執行緒加一0
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一1
我減一完畢了--------------------------喚醒其他執行緒加一0
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一1
我減一完畢了--------------------------喚醒其他執行緒加一0
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一1
我減一完畢了--------------------------喚醒其他執行緒加一0
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一1
我減一完畢了--------------------------喚醒其他執行緒加一0
我減一完畢了--------------------------喚醒其他執行緒加一-1
我減一完畢了--------------------------喚醒其他執行緒加一-2
我減一完畢了--------------------------喚醒其他執行緒加一-3
我減一完畢了--------------------------喚醒其他執行緒加一-4
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一-3
我減一完畢了--------------------------喚醒其他執行緒加一-4
我減一完畢了--------------------------喚醒其他執行緒加一-5
我減一完畢了--------------------------喚醒其他執行緒加一-6
我減一完畢了--------------------------喚醒其他執行緒加一-7
我減一完畢了--------------------------喚醒其他執行緒加一-8
我減一完畢了--------------------------喚醒其他執行緒加一-9
我減一完畢了--------------------------喚醒其他執行緒加一-10
我減一完畢了--------------------------喚醒其他執行緒加一-11
我減一完畢了--------------------------喚醒其他執行緒加一-12
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一-11
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一-10
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一-9
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一-8
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一-7
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一-6
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一-5
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一-4
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一-3
比如說:當值為0時,2個加操作被喚醒了,同時執行如下程式碼,會造成加1加兩次
if(number!=0){
//等待
this.wait();
}
number++;
但是如果改成如下判斷,就只會執行一次加1
while(number!=0){
//等待
this.wait();
}
number++;
if 改為 while 判斷
package com.zjl;
/**
* Created by zjl
* 2020/11/20
**/
/*
* 1、執行緒之間的通訊問題:生產者和消費者問題!
* 2、執行緒交替執行,A B 操作同一個變數 num = 0
* 3、A num+1
* 4、B num-1
* */
public class Test {
public static void main(String[] args) {
Data data = new Data();
new Thread(()->{
for (int i = 0; i < 10; i++) {
try {
data.increment();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
new Thread(()->{
for (int i = 0; i < 10; i++) {
try {
data.decrement();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
new Thread(()->{
for (int i = 0; i < 10; i++) {
try {
data.increment();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
new Thread(()->{
for (int i = 0; i < 10; i++) {
try {
data.decrement();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
}
}
//等待-----》業務-----》通知
class Data{ //數字,資源類
private int number = 0;
//+1
public synchronized void increment() throws InterruptedException {
while (number!=0){
//等待
this.wait();
}
number++;
System.out.println("我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一" + number);
this.notifyAll();
}
//-1
public synchronized void decrement() throws InterruptedException {
while (number == 0){
//等待
this.wait();
}
number--;
System.out.println("我減一完畢了--------------------------喚醒其他執行緒加一" + number);
this.notifyAll();
}
}
執行結果
/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/bin/java "-javaagent:/Users/zhangjianlong/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/193.5662.53/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=59913:/Users/zhangjianlong/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/193.5662.53/IntelliJ IDEA.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath /Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/deploy.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/ext/cldrdata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/ext/dnsns.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/ext/jaccess.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/ext/jfxrt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/ext/localedata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/ext/nashorn.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/ext/sunec.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/ext/sunjce_provider.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/ext/sunpkcs11.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/ext/zipfs.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/javaws.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/jfxswt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/management-agent.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/plugin.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/lib/ant-javafx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/lib/dt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/lib/javafx-mx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/lib/jconsole.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/lib/packager.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/lib/sa-jdi.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/lib/tools.jar:/Users/zhangjianlong/testCode/JUC-study/target/classes:/Users/zhangjianlong/apache-maven-3.6.3/repository/org/projectlombok/lombok/1.18.8/lombok-1.18.8.jar com.zjl.Test
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一1
我減一完畢了--------------------------喚醒其他執行緒加一0
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一1
我減一完畢了--------------------------喚醒其他執行緒加一0
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一1
我減一完畢了--------------------------喚醒其他執行緒加一0
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一1
我減一完畢了--------------------------喚醒其他執行緒加一0
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一1
我減一完畢了--------------------------喚醒其他執行緒加一0
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一1
我減一完畢了--------------------------喚醒其他執行緒加一0
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一1
我減一完畢了--------------------------喚醒其他執行緒加一0
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一1
我減一完畢了--------------------------喚醒其他執行緒加一0
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一1
我減一完畢了--------------------------喚醒其他執行緒加一0
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一1
我減一完畢了--------------------------喚醒其他執行緒加一0
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一1
我減一完畢了--------------------------喚醒其他執行緒加一0
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一1
我減一完畢了--------------------------喚醒其他執行緒加一0
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一1
我減一完畢了--------------------------喚醒其他執行緒加一0
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一1
我減一完畢了--------------------------喚醒其他執行緒加一0
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一1
我減一完畢了--------------------------喚醒其他執行緒加一0
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一1
我減一完畢了--------------------------喚醒其他執行緒加一0
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一1
我減一完畢了--------------------------喚醒其他執行緒加一0
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一1
我減一完畢了--------------------------喚醒其他執行緒加一0
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一1
我減一完畢了--------------------------喚醒其他執行緒加一0
我加一完畢了+++++++++++++++++++++++++喚醒其他執行緒減一1
我減一完畢了--------------------------喚醒其他執行緒加一0
Process finished with exit code 0
相關文章
- 生產者與消費者問題
- linux 生產者與消費者問題Linux
- 執行緒虛假喚醒問題剖析執行緒
- java實現生產者消費者問題Java
- 作業系統—生產者消費者問題詳解作業系統
- python中多程式消費者生產者問題Python
- 面試必問:訊號量與生產者消費者問題!面試
- 生產者消費者問題-C++程式碼實現C++
- python中多執行緒消費者生產者問題Python執行緒
- 生產消費問題
- java多執行緒之消費生產模型-使用synchronized解決虛假喚醒Java執行緒模型synchronized
- 虛假喚醒
- GoLang中生產者消費者模式解決併發問題Golang模式
- 生產者消費者
- 執行緒同步介紹及 生產者消費者問題舉例 C#版執行緒C#
- 訊號量實現生產者消費者(程式碼邏輯有問題,不適合多個消費者,不常用)
- synchronized同步程式+生產者消費者模式(訊號燈)解除可能出現的資源問題synchronized模式
- Thinking in Java---執行緒通訊+三種方式實現生產者消費者問題ThinkingJava執行緒
- java學習回顧---生產者與消費者問題以及多執行緒補充Java執行緒
- 生產者消費者模型模型
- 生產者消費者模式模式
- Java多執行緒程式設計(同步、死鎖、生產消費者問題)Java執行緒程式設計
- 中消協:網路遊戲產品不得虛假宣傳或誤導消費者遊戲
- python 生產者消費者模式Python模式
- 生產消費者模式模式
- 多執行緒——虛假喚醒執行緒
- ActiveMQ 生產者和消費者demoMQ
- 九、生產者與消費者模式模式
- 中國消費者協會:近4成消費者在直播購物中遭遇消費問題
- javase學習記錄之------生成者消費者之等待喚醒機制Java
- 併發王者課-青銅10:千錘百煉-如何解決生產者與消費者經典問題
- Java實現生產者和消費者Java
- 生產者與消費者之Android audioAndroid
- 新手練習-消費者生產者模型模型
- java編寫生產者/消費者模式的程式。Java模式
- Qt基於QSemaphore的生產者消費者模型QT模型
- 阻塞佇列和生產者-消費者模式佇列模式
- 傳教士與食人者問題pythonPython