This is a model of a producer consumer problem in a Java video tutorial by a horse soldier teacher.[Java]View Plaincopy
Public class produceconsumer{
public static void Main (string[] args) {
Syncstack ss = new Syncstack ();
Producer Pro = new Producer (ss);
Consumer con = new
Large-scale enterprise distributed internet e-commerce platform, launched pc++app+ cloud Service cloud business platform system, including business-to-business, consumer-to-Mobile, on-the-trade, new retail, live e-commerce and other sub-platforms.Based on the concept of micro-service design, combined with springCloud some of the best projects, such as service discovery, governance, configuration management, routing load, security control and other exc
producer individual*/ Private intID; Privatemonition PC; Publicproduc (monition monition) {ID= ++Total ; PC=monition; } @Override Public voidrun () { while(true) { if(Pc.put ()) {//If the operation succeeds in printing the buffer stateSystem.out.println (ID + "number producer:" +pc.getstatus ()); } } }}/ PackageEntity.producerconsumer; Public classConsuImplementsRunnable {/*** Statistics of the number of consumers*/ Private Static intTotal = 0; /*** ID of the
frame: jQuery1.9.CSS Framework: Bootstrap 4 MetronicClient authentication: Jqueryvalidation Plugin.Rich Text: CkecitorFile Management: CkfinderDynamic tab: JerichotabData table: Jqgriddialog box: JQuery jboxTree structure controls: JQuery ZtreeOther components: Bootstrap 4 metronic3. SupportServer middleware: Tomcat 6, 7, Jboss 7, WebLogic 10, WebSphere 8Database support: Currently only support MySQL database, but not limited to the database, the next version of the upgrade multi-data source sw
to remove products, producers wait for consumers to consume products, thereby adding products to the space. Wait for each other, thus the deadlock occurs.Three ways in which Java solves threading models1. Wait () and notify ()Import Java.util.linkedlist;public class Producerconsumer {private linkedlist2, await () and signal (), the way the thread locksPackage Sort;import Java.util.linkedlist;import Java.util.concurrent.locks.condition;import Java.
Package Com.subject01;import Java.util.priorityqueue;import Java.util.concurrent.locks.condition;import Java.util.concurrent.locks.lock;import java.util.concurrent.locks.reentrantlock;/** * condition is only present in Java 1.5, It is used instead of the traditional object's Wait (), notify () to implement inter-threading collaboration, compared to wait (), notify () with object, * using Condition's await (), signal () This approach enables inter-thre
Input implements Runnable { Privateperson person; PublicInput (person person) { This. person = person; } @Override Public voidRun () {intx =0; while(true) {synchronized (person) {if(Person.flag) {if(x = =0) {//judgment interval to produce different peoplePerson.name ="Tom"; Person.sex ="Male"; }Else{Person.name ="Zhang San"; Person.sex ="female"; } x = (x +1) %2;//interval to produce different peoplePerson.flag =false;//Put it once, take it oncePerson.notify ();//wake-up thread of a person}E
--; System.out.println ("Consumers are consuming Xiaomi mobile phones sell 1, the current number of products:" +con.currentnum+ "department"); }Else if(Con.currentnum = = 0) {//If you don't have a cell phoneSystem.out.println ("The phone has been bought, consumers stop spending, is waiting for production ..."); Try{con.wait ();//suspend consumption and release locks}Catch(interruptedexception e) {e.printstacktrace (); } }//else if}//syn Try{Thread.Sleep (14
Big Data Architecture Development mining analysis Hadoop Hive HBase Storm Spark Flume ZooKeeper Kafka Redis MongoDB Java cloud computing machine learning video tutorial, flumekafkastorm
Training big data architecture development, mining and analysis!
From basic to advanced, one-on-one training! Full technical guidance! [Technical QQ: 2937765541]
Get the big data video tutorial and training address
Byt
Use Linkedblockingqueue in Java to implement producer, consumer mode
Linkedblockingqueue implementation is thread-safe, which realizes FIFO (first-in first out) and other characteristics. is the first choice as producer consumers, Linkedblockingqueue can specify capacity, or can not be specified, not specified, the default is the largest integer.max_value, which mainly used put and take method, The put meth
Big Data Architecture Development mining analysis Hadoop HBase Hive Storm Spark Flume ZooKeeper Kafka Redis MongoDB Java cloud computing machine learning video tutorial, flumekafkastorm
Training big data architecture development, mining and analysis!
From basic to advanced, one-on-one training! Full technical guidance! [Technical QQ: 2937765541]
Get the big data video tutorial and training address
Byt
Import Java.util.linkedlist;import java.util.queue;import java.util.random;/** * Simple Java program to demonstrate how T o use Wait, notify and Notifyall () * method in Java by solving producer consumer problem. * * @author Javin Paul */public class Producerconsumerinjava {public static void main (String args[]) {SYSTEM.O Ut.println ("How to use Wait and
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.