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 are the differences between sleep () and yield () in java

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces what are the differences between sleep () and yield () in java, which can be used for reference by interested friends. I hope you can learn a lot after reading this article.

2.4 the difference between sleep () and yield ()

1) sleep () brings the current thread into a stagnant state, so the thread executing sleep () will definitely not execute within a specified period of time; yield () just brings the current thread back to the executable state, so the thread executing yield () may be executed again as soon as it enters the executable state.

2) sleep () can give low-priority threads the opportunity to execute, of course, it can also give the same priority and high-priority threads the opportunity to execute; yield () can only make the same priority threads have the opportunity to execute.

Example 15:

Class TestThreadMethod extends Thread {

Public static int shareVar = 0

Public TestThreadMethod (String name) {

Super (name)

}

Public void run () {

For (int item0; I

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