thread pool, connection pool, and so on. Therefore, it is also necessary to know the reason why, and we then explain the code to illustrate the focus of this implementation code:1. There is only one resource pool.2.synchronized, is the lock object, simply say: An object has and only a lock, when there are more than one synchronized method or block of code to request a lock on the object, at the same time, only one thread will get the lock and run, the others are blocked.3.wait, refers to the th
The Kafka version I use is: 0.7.2
The JDK version is: 1.6.0_20
Http://kafka.apache.org/07/quickstart.html The official example is not very complete, the following code is my supplement and can be run after compiling.
Producer Code
[Java] View Plain copy importjava.util.*; importkafka.message.message; Import kafka.producer.ProducerConfig; importkafka.javaapi.producer.producer; Import kafka.javaapi.producer
Producer, consumer, fixed-length buffer, and thread can be interrupted externally
Import java. util. arrays;Import java. util. date;Import java. util. Collections list;Import javax. Swing .*;
Public class producerconsumer {
Public static jframe inst;
Public static void main (string [] ARGs ){
Bufferlock buffer = new bu
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
Consumer all back to the mall development app Platform: 151.1222.4001 (synchronous) consumption of all-back system development, consumption of the full return to the development of the mall, consumption of all back to the development of the model, consumption of the full return to the platform development, consumer all back to the app development, consumption of all back to the model,
Thread communication example-producer consumer issuesThis kind of problem describes a situation, assume that the warehouse can only store one product, the producer will produce the product into the warehouse, the consumer will take away the product of the warehouse. Assuming there is no product in the warehouse, the producer can put the product into the warehouse and have the product, stop the production an
; ImportKafka.producer.ProducerConfig; /** Own in the source server writes the producer to Kafka inserts the data, note the file "Producer.properties puts under the Linux the jar file same directory * listens to a directory the file data then writes Kafka * Nohup Java-jar Portallog_producer.jar portallog/var/apache/logs portallog.position >/home/sre/portalhandler
In multithreaded development, one of the most classic models is the producer consumer model, they have a buffer, the buffer has the maximum limit, when the buffer is full, the producer is unable to put the product into the buffer, of course, when the buffer is empty, the consumer can not take out the product, whichRelated to the conditional judgment in multi-threading,
. Production here is to take the wake of consumption, wake up is the consumption of the thread.If it is two locks, then the production can only be used for production, consumption can only be used for consumption (this is said in the previous practice), they can both run at the same time, will cause problems.And we now produce inside in the operation of time, consumption is not moving, this is called the same lock.Producer_con producer Monitor, Consumer_con
Honghu Cloud Business Enterprise Distributed internet e-commerce platform, launched pc++app+ cloud Service cloud business platform system, including business-to-commerce, consumer-to-business, on-the-net, new retail, live e-commerce and other sub-platforms.Distributed, microservices, Cloud architecture e-commerce platform Java B2B2CTechnical SolutionsDevelopment language:
Http://www.cnblogs.com/zyp4614/p/6033757.html(Java and operating system process synchronization problem (i) ———— mutex issues)Today is the most classic producer of consumer problems, the simplest version, that is, only one buffer, the buffer can only put one item, that is, regardless of the mutual exclusion relationship.Simple analysis: Producers can put products in buffers when the buffer is empty, consume
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.