Remember the first time to do the Java problem, see "write producer consumer problems", but also think it is related to the factory model. Now it is thunder to think about it.Java's producer consumer problem is the multi-threaded concurrent operation of the same resource buffer, when the resource buffer is full, the thread continues to add data, you should make i
("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 ("produced:" + M + "Total" + Ss.index + "a steamed bun");
It is inappropriate to test on the
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
In the previous producer consumer program, the data produced by the producer at a time can be read multiple times by the consumer. Obviously, this does not meet our requirements. In this regard, the above procedures are improved:
1) The producer produces data once and the consumer obtains the data once;
2) A bucket can only store one pair of data
We will use the
This is a classic example of thread synchronization, the source code is as follows:[Java]View Plaincopy
"FONT-SIZE:16PX;"> Packagedemo.thread;
/**
* Classic producer and consumer issues: producers constantly store their products in warehouses and consumers consume products from warehouses.
* Both producers and consumers can have a number of. Storage capacity is limited, storage is not availabl
This article describes the Java multithreading solution to the problem of producer consumers. Share to everyone for your reference. The specific analysis is as follows:
The title is this:
Adopt Java Multithreading Technology, design and implement a program that conforms to the problem of producer and consumer. Operates on an object (the barrel) with a maximum c
IntroductionProducer and consumer issues are a classic problem in threading models: producers and consumers share the same storage space during the same time period , as shown in, producers store data in space, and consumers access data, If not coordinated, the following conditions may occur:Producer Consumer ChartStorage space is full, and producers occupy it, consumers wait for producers to give up space
+ +; + } - + } A at}Consumer's thread, this time super simple ~~~1 Public classGetThreadImplementsRunnable {2 PrivateStudent S;3 4 PublicGetThread (Student s) {5 This. S =s;6 }7 8 Public voidrun () {9 while(true) {Ten s.get (); One } A } -}Consumer's thread, this time super simple ~~~1 Public classDemo {2 Public Static voidMain (string[] args) {3 //shared data, created externally, as parameters, by constructing common4
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 option provides the lowest latency but the weakest durability guarantees (some data would be lost when a server fails) .1, which means that the producer gets a acknowledgement after the leader replica have received the data. This option provides better durability as the client waits until the server acknowledges the request as successful (only M Essages that were written to the Now-dead leader and not yet replicated would be lost).-1, which means that the producer gets a acknowledgement
Reference: https://www.jianshu.com/p/9e72b3942c59The reason is Num.patitions = 1 in the Kafka cluster kafka/config/server.properties file. The partition default value needs to be modified.Partitions the number of partitions nodes created by default when creating topic, only the newly created topic takes effect, and all tries to set a reasonable value at the time of project planning. You can also dynamically
In the last article we analyzed the metadata update mechanism, which involves a problem, that is, sender how to communicate with the server, that is, the network layer. Like many Java projects, the Kafka client's network layer is also used for Java NIO, which is then encapsulated in the above layer.
Let's take a look at the section between the sender and the serv
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.