Java???????????????????
???????????? ???????[ 2016/3/11 14:20:31 ] ??????????????????? ???????
????2??await()??signal()?????????????
package sort;
import java.util.LinkedList;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
public class ProducerConsumer {
private LinkedList<Object> myList = new LinkedList<Object>();
private int MAX = 10;
private final Lock lock = new ReentrantLock();
private final Condition full = lock.newCondition();
private final Condition empty = lock.newCondition();
public ProducerConsumer() {
}
public void start() {
new Producer().start();
new Consumer().start();
}
public static void main(String[] args) throws Exception {
ProducerConsumer s2 = new ProducerConsumer();
s2.start();
}
class Producer extends Thread {
public void run() {
while (true) {
lock.lock();
try {
while (myList.size() == MAX) {
System.out.println("warning: it's full!");
full.await();
}
Object o = new Object();
if (myList.add(o)) {
System.out.println("Producer: " + o);
empty.signal();
}
} catch (InterruptedException ie) {
System.out.println("producer is interrupted!");
} finally {
lock.unlock();
}
}
}
}
class Consumer extends Thread {
public void run() {
while (true) {
lock.lock();
try {
while (myList.size() == 0) {
System.out.println("warning: it's empty!");
empty.await();
}
Object o = myList.removeLast();
System.out.println("Consumer: " + o);
full.signal();
} catch (InterruptedException ie) {
System.out.println("consumer is interrupted!");
} finally {
lock.unlock();
}
}
}
}
}
????3?????????е???
import java.util.concurrent.*;
public class ProducerConsumer {
// ???????????????
private LinkedBlockingQueue<Object> queue = new LinkedBlockingQueue<Object>(10);
public ProducerConsumer() {
}
public void start() {
new Producer().start();
new Consumer().start();
}
public static void main(String[] args) throws Exception {
ProducerConsumer s3 = new ProducerConsumer();
s3.start();
}
class Producer extends Thread {
public void run() {
while (true) {
try {
Object o = new Object();
// ??????????
queue.put(o);
System.out.println("Producer: " + o);
} catch (InterruptedException e) {
System.out.println("producer is interrupted!");
}
// }
}
}
}
class Consumer extends Thread {
public void run() {
while (true) {
try {
// ??????????
Object o = queue.take();
System.out.println("Consumer: " + o);
} catch (InterruptedException e) {
System.out.println("producer is interrupted!");
}
// }
}
}
}
}
????????
???????????????£??????????????????????????????????????????????????????????洢?????????????????????LinkedBlockingQueue???????
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????
??????
Java???????????Щ???????????????Java????????????????Java?б???Map????????Java Web???????????????Java??????????????д?????Java????????7???????????????????????(java .net ?????)???Java??????????Python??????Java webdriver??λ????????′????е?????Java??д??????????????????Java???????????????JavaScript????????????Java?????????????????? Java???????10??????????????Java?м????????????????java???????ü???????????м???????????????????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11????????
?????????App Bug???????????????????????Jmeter?????????QC??????APP????????????????app?????е????????jenkins+testng+ant+webdriver??????????????JMeter????HTTP???????Selenium 2.0 WebDriver ??????