The classic producer consumer problem simulation. This program simulates the simplest case-single buffering. In order to simulate the actual situation, the consume item and the produce item were added with the delay, and the different generation consumption rate could be simulated by modifying the delay.
[Code]
[/co/*** Single buffer consumer-producer problem.* by Xu (xusiwei1236@163.com).* */public class
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)
Producer and consumer mode 1. QueueAdvanced First Out2. StackAdvanced Post-outA synchronized, thread-safe queue class is provided in the Python queue module, including FIFO (first-in, first-out) queue Queue,lifo (back-in-first-out) queue Lifoqueue, and priority queue priorityqueue. These queues implement the lock primitives (which can be understood as atomic operations, i.e. either not done or done) and can be used directly in multiple threads. Queues
Before I felt very simple, but one interview let me write on the paper, actually did not write to disgrace ah.Producer consumer problem (Producer-consumer problem): Producers constantly produce products, consumers take away the products produced by producers. The producer produces the product and puts it into an area where consumers remove data from it.The problem: to ensure that producers do not add data w
Producer-consumption patterns, which typically have two types of threads, that is, several producer threads and several consumer threads. Producer threads are responsible for submitting user requests, and consumer threads are responsible for dealing specifically with the tasks submitted by the producer. The two communi
Since the previous postI have already worked on literacy, so I should start to talk about some specific programming technical issues. However, before entering the specific technical details, we must first understand the question: how to determine the data unit? Only by clearly analyzing data units can we develop the technical design later.
★What is a data unit?What is data unit pinching? Simply put, each producer put in a buffer zone is a data unit.
Package com. jzm. thread;
Class q {Int N;Boolean valueset = false;Synchronized int get (){// The value has not been put. Wait for the put value.If (! Valueset ){Try {Wait ();} Catch (interruptedexception e ){System. Out. println ("interrupt caught ");}}
System. Out. println ("got:" + n );Valueset = false;Notify ();Return N;}Synchronized void put (int n ){// Put the value, wait for the got to take the value, and then place the valueIf (valueset ){Try {Wait ();} Catch (interruptedexception e ){Sys
This article turned from programming blog: http://program-think.blogspot.com/2009/03/producer-consumer-pattern-1-data.html
★What is a data unit?Simply put, each producer put in a buffer zone is a data unit. Each consumer fetches data from the buffer zone. For sending example, we can regard each letter as a data unit.
However, this introduction is too simple to help everyone analyze this stuff. So let's ta
This example is used to familiarize yourself with the development process of JMS.
The result is that a servlet sends a message to a message driven Bean (MDB. The server is glassfish3.1.
First, create some JMS resources, including connectionfactory and a queue. In this example, it is a ptp jms link.
Establish a connection Factory
Start glassfish-> resources-> JMS resources-> link factory-> Create
The pool name (that is, the JNDI name) is JMS/queueconnectionfactory.
Select javax. JMS. queueconne
1.Before the company has a project, there is a thread to receive a TCP connection and then put the socket into the queue, 10 threads processing socket data, but 10 threads are still not processed, the client connected and closed, the service end processing data through the socket sent, the socket has been closed.For producer-consumer issues, be sure to set the buffer size, and when the buffers are full, the producers will not join the data. The use of
Producer-Consumer modelling issues/** * Using blocking queues to implement producer-consumer models * Blocking queues only allows elements to be accessed in a FIFO * @author Bingyue * */public class Producercustomerpattern {public static V OID Main (string[] args) {//producer and consumer shared storage area blockingqueue Implement
Introduction to the basic API of the multi-thread demo program for producer consumer in linux: intpthread_create (pthread * thread, pthread_attr_t * attr, void * (* start_routine) (* void ), void * arg); the first parameter is the second parameter pointing to the thread... introduction to the basic API of the multi-thread demo program for producer consumer in linux: int pthread_create (pthread * thread, pth
import Java.util.arraylist;import java.util.List;/** * Created by the CCC on 16-4-27.*/ Public classTest { Public Static voidMain (string[] args) {gunclip clip=NewGunclip (); Producer P=NewProducer (clip); Customer C=Newcustomer (clip); P.start (); C.start (); }}/*first I'm going to have a magazine,*/classGunclip {//Mag PrivatelistNULL;//used to put bullets . PrivateBoolean bfull =false;//It is important to understand the Boolean varia
Analysis of producer and consumer operation instances using python conditional variables, and python conditional variables
This article describes the producer and consumer operations of python conditional variables. We will share this with you for your reference. The details are as follows:
Mutex lock is the simplest thread synchronization mechanism. In the face of complicated thread synchronization problem
Producer consumer problem is a very classic problem in multithreading concurrency. I am here to implement a c++11-based, single-producer single-consumer version for your reference.#include Notice that I determine whether the items in the Item_buffer are empty or full: the position of the producer and the consumer is equal, if the position is empty then buffer is
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.