Crawlerthread, which is to search for files in a file hierarchy that conform to the index criteria and put their names in the work queue. A consumer task is given in Indexerthread, which is to remove the file names from the queue and index them.The example comes from the Java Concurrency Programming combat.class Crawlerthread extends Thread {private final blockingqueueThe producer-
Preface: Recently in learning Java Multi-threading, see Importnew Online has a netizen translation of an article "block queue to achieve producer consumer model". In this article, the blocking queue in Java's concurrent package is used. After reading, implement the blocking queue by itself.(i) PreparationIn multi-threading, producer-consumer issues are a classic
Label:First, the environment
One Centos6.5 console
Mongo 3.0
kafka_2.11-0.8.2.1
Storm-0.9.5
Zookeeper-3.4.6
Java 1.7 (later because the jar packaged on Mac is not run by the 1.8 compilation, instead Java 1.8)
Other environment Temporary
Second, the operation starts
Start ZookeeperVerify that the configuration is correct, and that the configuration is self-searching
Examples of producer and consumer modes are used to explain the basic Java class methods such as wait, notify, notifyAll, and yypolicyall.
Wait (), Policy (), and policyall () are Java-based java. lang. Object methods.
General ExplanationWait (): wait for other threads to wake up in the current thread.Y (): Wake up a t
Java multithreading (synchronization and deadlock, producer and consumer issues)
First, let's look at the synchronization and deadlock issues:
A deadlock means that A owns banana and B owns apple.
A said to B: If you give me apple, I will give you banana.
B said to a: If you give me banana, I will give you apple.
However, both A and B are waiting for the reply from the other party, so the final result is
, - //so the wake-up process is blocked, and if the consumer thread wakes up, the consumer thread starts to work) theSystem.out.println (Thread.CurrentThread (). GetName () + "production of a product current surplus quantity:" +curnum); the Try { theThread.CurrentThread (). Sleep (250);//control the speed of production the -}Catch(interruptedexception e) { th
(container, Producermonitor, consumermonitor)); Thread C2=NewThread (NewConsumer (container, Producermonitor, consumermonitor)); P1.start (); P2.start (); C1.start (); C2.start (); }}At present, the first to write, the temporary operation is not a problem, if there is a problem, please crossing pointed out.Areas to be improved:1. Container there is no better way to implement2. Container can have multiple, so that you can randomly find a usable container assigned to produ
Introduction
The producer and consumer problems are classic issues in the thread model:Same time periodIntranet sharingSame bucketAs shown in, if the producer stores data into the space and the consumer uses the data, the following situations may occur if the data is not coordinated:
Producer consumer Diagram
The storage space is full, and the producer occupies
(); }Because after another thread notifyall, after waking this thread, it is impossible to confirm that the test condition must be met at this time. There is no problem with two threads, but there will be problems with more threads, because you cannot confirm that you are being awakened by the producer thread, and that there may be other threads that have changed the state variable before waking (this is the message in the drop), so there will be an exception. It is therefore necessary t
Kafka officially provided two scripts to manage the topic, including additions and deletions to topic. Where kafka-topics.sh is responsible for the creation and deletion of topic, kafka-configs.sh script is responsible for topic modification and query, but many users are more inclined to use the program API to operate topic. The previous article mentioned how to
Description of the error:Under the Kafka installation directory, execute $ bin/zookeeper-server-start.sh config/zookeeper.properties Unrecognized VM option ' usecompressedoops 'Error:clould not create the Java vritual machine.ERROR:A Fatal exception has occurres. Program would exit. Workaround:Locate bin/kafka-run-class.sh file, use Vim to open, this versio
no oh, there is waiting to be consumed, there is no production data ready to be consumed. - if(s.flag) { the Try { - s.wait (); -}Catch(interruptedexception e) { - //TODO auto-generated Catch block + e.printstacktrace (); - } + } A at //once the flag is marked False, execute the following code - - if(x% 2 = = 0) { -S.name = "
Java: producer and consumer issues
I remember the first time I made a java question, I saw "Writing producer and consumer problems" and thought it was related to the factory model. Now, I think it's a crash.Java producer and consumer issues are actually about multi-thread co
Package com.cn.test3; Java multithreaded simulation producer consumer issues//producerconsumer is the main class, producer producers, consumer consumers, product products//storage WarehouseComments: I wrote the output below the program, you can look at it, in fact very easy, you imagine the product from production, to take out a production line, we define two thr
1 // The standard idiom for calling the wait 2 synchronized (sharedobject) {3 while (condition) {4 sharedobject.wait (); releases lock, and reacquires on Wake up5 }6 // do action based upon condition e.g. take or put to queue 7 }Canonical code template using the wait and notify functions.The purpose of using wait in the while loop is to check whether the condition is satisfied before and after the thread is awakened, and if the condition is not changed,
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.