Get the App
SLTechnology News&Howtos  ›  Development  › 

How to create two thread simulation dialogs by Java

Shulou Source: shulou.com Published: 2022-06-03 14:17:40 10月03日 Update

This article mainly explains "Java how to create two threads to simulate dialogue," interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let Xiaobian take you to learn "Java how to create two threads to simulate dialogue"!

code content

Consumers, responsible for taking away information produced by producers

/** * @auther:: 9527 * @Description: Consumer * @program: Multithread * @create: 2019-08-10 10:45 */public class Consumer extends Thread{ private MiddleMan mid = null; public Consumer() { } public Consumer(MiddleMan movie) { this.mid = movie; } @Override public void run() { //loop 50 movie messages for (int i = 0; i taken away from production is taken away MiddleMan mid = new MiddleMan(); Thread producer = new Thread(new Producer(mid)); Thread consumer = new Thread(new Consumer(mid)); producer.start(); consumer.start(); }} At this point, I believe that everyone has a deeper understanding of "Java how to create two threads to simulate dialogue," may wish to actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!

Tags: Thread production consumption consumer information producer two dialogue content method logo movie learning loop control practical deeper code entry interest Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Xiaomi Shulou Technology MySQL Huawei