) warehouse, and then unlocked by unlock (). (04) in the main thread main, we will create a new 1 producer Mpro and create 1 new consumer MCUs. They produce/consume products separately from the warehouse. According to the number of production/consumption in Main, the final remaining product of the warehouse should be 50. The results of the operation are in line with our expectations! There are two problems with this model:(01) In reality, th
("consumption:---------" + sm[index] + "Total" + index + "a steamed bun");
return Sm[index];
}
}
Class Producer implements Runnable
{
Stackbasket ss = new Stackbasket ();
Producer (Stackbasket ss) {
THIS.SS = SS;
}
/**
* Show production process.
*/
public Void Run () {
For (int i = 0;i 20;i++) {
Mantou m = new Mantou (i);
Ss.push (m);
System.out.println ("pr
Java.util.concurrent.executorservice;import Java.util.concurrent.executors;import Java.util.concurrent.linkedblockingqueue;public class Main {public static void Main (string[] args) throws interruptedexception{blockingqueueUsing Notifyall and waitPackage Com;import Java.util.list;public class Consumer implements Runnable{private list Package Com;import Java.util.list;import Java.util.random;public class Producer implements Runnable {private list Pa
(canrun) to determine whether the "running status" is used.
Thread-based class (CODE)
Package COM. fox. producerconsumer;
6. producer: The producer produces goods under certain conditions (containers are not satisfied) and stores the goods in the database. After an action is completed, yield will notify the "top-up" task to complete, to prevent continuous production, tired of working. Joke!
This is a common mode for Java Development. It allows the program to call each other between producers and consumers during design.
Three objects need to be created in the mode: producer consumer warehouse
Producer: Put the products produced into the total warehouse
Consumer: extracts products from the warehouse for consumption.
Warehouse: A synchronization meth
DhpeitopicThird, use Java to operate Kafka. 3.1 Create a topic,Create a topic using the method of creating topic commands in "2.6" , named dhpeitopic. 3.1 Send data kafkaproductor. mainly two steps, the first step to prepare the parameters of the connection Kafka, in fact, the main configuration of a broker ip:port; the second step to the specified Topic sen
; + This. Age =Age ; - + //Once you have the data modification tag, and wake up A This. Flag =true; at This. Notify (); - } - - //Synchronous Fetch Method - Public synchronized voidget () { - //wait if there's no data in if(! This. Flag) { - Try { to This. Wait (); +}Catch(interruptedexception e) { - e.printstacktrace (); the } * } $ //Get DataPanax NotoginsengSystem.out.pri
Exchanger is a concurrency tool under the Java.util.concurrent class library. The following is a description of exchanger in the Java API documentation.A synchronization point at which threads can pair and swap elements within pairs. Each thread presents some object in entry to the Exchange method, matches with a partner thread, and receives its partner ' S object on return. An Exchanger is viewed as a bidirectional form of a synchronousqueue. Exchang
This is a model of a producer consumer problem in a Java video tutorial by a horse soldier teacher.[Java]View Plaincopy
Public class produceconsumer{
public static void Main (string[] args) {
Syncstack ss = new Syncstack ();
Producer Pro = new Producer (ss);
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.