* 作为学习笔记,供自己以后复习
* 开源给大家,帮助有需要的基友,哈哈
* 共同探讨学习
- 稀疏数组与队列
- 链表
- 栈
- 递归
- 排序算法
【记录平时积累+Java学习】目的是涵盖大部分Java工程师所需知识^_^
* 作为学习笔记,供自己以后复习
* 开源给大家,帮助有需要的基友,哈哈
* 共同探讨学习
package com.ph.juc;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
class ShareData{
private int number = 0;
private Lock lock = new ReentrantLock();
private Condition condition = lock.newCondition();
public void increment() throws Exception{
lock.lock();
try{
// 1. 判断
while (number != 0){
// 等待不能生产
condition.await();
}
// 2. 干活
number++;
System.out.println(Thread.currentThread().getName() + "\t " + number);
// 3.通知、唤醒
condition.signalAll();
}catch(Exception e){
e.printStackTrace();
}finally{
lock.unlock();
}
}
public void decrement() throws Exception{
lock.lock();
try{
// 1. 判断
while (number == 0){
// 等待不能生产
condition.await();
}
// 2. 干活
number--;
System.out.println(Thread.currentThread().getName() + "\t " + number);
// 3.通知、唤醒
condition.signalAll();
}catch(Exception e){
e.printStackTrace();
}finally{
lock.unlock();
}
}
}
/**
*/
public class ProdConsumer_TraditionDemo {
public static void main(String[] args) throws Exception{
ShareData shareData = new ShareData();
new Thread(()->{
for (int i = 1; i <= 5; i++) {
try {
shareData.increment();
} catch (Exception e) {
e.printStackTrace();
}
}
},"AA").start();
new Thread(()->{
for (int i = 1; i <= 5; i++) {
try {
shareData.decrement();
} catch (Exception e) {
e.printStackTrace();
}
}
},"BB").start();
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.