Tags: User ase mode Cache code log SHM nbsp inf1.1 RequirementsDatabase 3 million user data, traverse get all users, various combinations associated, get to a new JSON, save to Redis.1.2 DifficultiesDatabase is much more, it is impossible to single-threaded query all the data to memory.1.3 SolutionsMulti-threaded reading, the producer gets 200 data each time, the consumer goes to consume. (This is mainly based on MySQL paging to get the next 200 data)
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, consumers can take a product when the buffer is not
Tags: thread producer consumer Mode The producer and consumer modes are shown in. Blog purpose: Use graphs to speak. Sample Code: Package COM. huan; public class produceconsumer {public static void main (string [] ARGs) {middleware = new middleware (); New thread (new producer (middleware )). start (); New thread (new consumer (middleware )). start () ;}}
Producer-consumer is an interesting algorithm. Its existence mainly serves two purposes. The first is to satisfy the producer's constant creation of resources, and the second is to satisfy the consumer's constant demand for resources. Of course, because space is limited, resources cannot be stored infinitely or requested infinitely.
Producer Algorithm
WaitForSingleObject(hEmpty, INFINITE); WaitForSin
Packagedemo;Importjava.util.Properties;ImportKafka.javaapi.producer.Producer;ImportKafka.producer.KeyedMessage;ImportKafka.producer.ProducerConfig; Public classProducer {Private FinalProducerproducer; Public Final StaticString TOPIC = "Test"; Privateproducer () {Properties props=NewProperties (); //The Kafka port is configured here .Props.put ("Metadata.broker.list", "192.168.152.20:9092"); //to configure the serialization class for valueProps.put ("Serializer.class", "Kafka.serializer.StringEn
Public Class Cell{ Bool Flags = False ; Int Result = 0 ; Public Void Write ( Int N){ Lock ( This ){If (Flags){ Try {Monitor. Wait ( This );} Catch (Threadstartexception E){Console. writeline (E );}}Result = N;Console. writeline ( " Write: {0} " , Result );Flags = True ;Monitor. Pulse ( This );}} Public Int Read (){ Lock ( This ){ If (! Flags){ Try {Monitor. Wait ( This );} Catch (Threadstartexception E){Console. writeline (E );}}Console. writeline ( " Read: {0} " , Result );Flags = Fals
This is a creation in
Article, where the information may have evolved or changed.
In the actual business scenario, in order to improve the real-time performance of the system, reduce the pressure of log storage, the need to direct the production of logs to the message middleware, reduce the flume or flumted collection caused by the delay and pressure, this paper realizes the function:Implements a static call to the asynchronous producer AsyncproducerE
1, using the function to implement the producer consumer model(1), the source code is as follows:#!/usr/bin/python#_*_coding:utf-8_*_importthreadingimporttimeimportqueueimport Randomdefproducer (Name,que):whiletrue: ifque.qsize () (2), operation result:650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M01/89/80/wKioL1gV3Z6TTZnLAACEeavOGY0439.png-wh_500x0-wm_3 -wmp_4-s_3979700276.png "title=" Qq20161030194625.png "alt=" Wkiol1gv3z6ttznlaaceeavogy0
Producer Consumer
Producers create data, control traffic through intermediaries, and deliver it securely to consumers.Applicable environment
The speed of producer production data is inconsistent with the speed with which consumers process data, and intermediaries adjust the data pressure of consumers by caching and blocking.
Sample Example
4 producers produce products, put i
Public class Customer extends thread{ private Queue q; Public Customer (Queue q) { this.q = q; } public void Run () { for (int i = 0; i int value = Q.get (); } } } public class Producer extends thread{ private Queue q; Public Producer (Queue q) { this.q = q; } public void Run () { for (int i = 0; i Q.put (i); } } } public class Queue { int value; Boolean bfull = false; Synchronized public void
In the process, the producer is the thread of production data, and the consumer is the thread of consumption data. In multithreaded development, producers have to wait for the consumer to continue producing data if the producer is processing fast and the consumer processing is slow. Similarly, consumers must wait for producers if their processing power is greater than that of producers. To solve this proble
Design Patterns and concurrent producer-consumer patternsProducer-consumer mode is a classic multithreaded design pattern. It provides a good solution for collaboration between multiple threads.In producer-consumer mode, typically consists of two types of threads, that is, several producer threads and a number of consumer threads.
condition::timedwait (int seconds) {//Gets the current time of the struct timespec abstime; Clock_gettime (Clock_realtime, abstime); The current time plus the number of seconds to wait, constituting an absolute time value abstime.tv_sec + = seconds; Return pthread_cond_timedwait (m_cond, m_mutex, abstime);} int Condition::lock () {return pthread_mutex_lock (m_mutex);} int Condition::trylock () {return pthread_mutex_trylock (m_mutex);} INT Condition::unlock () {return pthread_mutex_unlock
The rookie encounters the signal volume, rubs the spark (only then will have the spark if not ripe). So the Internet search information and see "UNIX Environment Advanced Programming" to achieve a few small examples, master do not spray! These are very well written:Title Source: http://www.it165.net/os/html/201312/7039.htmlSignal volume and usage: http://www.cnblogs.com/hjslovewcl/archive/2011/03/03/2314341.htmlThe distinction between mutexes and semaphore famous toilet theory: http://koti.mbnet
#-*-coding:utf-8-*-"""multi-threaded producer, consumers using queue queues"""ImportQueueImportThreadingImport TimeImportRandomqueue= Queue.queue (3)#Create a queue of 3 sizesclassProducer (Threading. Thread):"""producers, writing data to the queue""" def __init__(self, queue): Super (Producer, self).__init__()#calling the parent class constructorSelf.queue =QueuedefRun (self): whiletrue:my_rand_double=r
I. Purpose of the experimentImplement a C program that simulates solving a limited buffering problem where consumers and producers generate and consume random numbersTwo. Experimental content
Buffer
The metadata type is Buffer_item, an array of size 1000, processed by the ring queue
Producer and Consumer Threads
Producers continue to perform the following two operations: consume a random number and produce two random number
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 capacity of 12 bullets. A
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.