Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the waiting notification mechanism of Java?

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Most people do not understand the knowledge points of this article "what is the waiting notification mechanism of Java", so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this article "what is the waiting notification mechanism of Java?"

Waiting Notification Mechanism of Java

In some cases, we need to share certain resources in a certain order among several or more threads. For example, in the producer-consumer relationship, in this relationship, it is always possible for the consumer to consume after the producer has produced the product; or in the father-son relationship, there is always a father before a son. However, before the introduction of the waiting notification mechanism, we often get the wrong situation.

Examples of consumers:

/ * =

* File: ThreadDemo07.java

* description: producer-consumer

* Note: some of the notes were added according to my own understanding.

* =

, /

/ / shared data objects

Class ShareData {

Private char c

Public void setShareChar (char c) {

This.c = c

}

Public char getShareChar () {

Return this.c

}

}

/ / producer thread

Class Producer extends Thread {

Private ShareData s

Producer (ShareData s) {

This.s = s

}

Public void run () {

For (char ch = 'Agar; ch)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report