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

How to explain the thread

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

Share

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

This article introduces you how to explain the thread, the content is very detailed, interested friends can refer to, hope to be helpful to you.

Thread scheduling

In java technology, threads are usually preemptive and do not require a time slice allocation process (a process that assigns equal cpu time to each thread). A common mistake is to think that "preemption" is "allocating time slices".

In the runtime environment on the Solaris platform, threads of the same priority cannot preempt each other's cpu time. However, in a windows platform running environment that uses time slices, you can preempt the cpu time of threads with the same or higher priority. Preemption is not absolute, but most JVM implementations show strict preemption in behavior. Throughout the implementation of JVM, there is no absolute preemption or time slice, but depends on the encoder's use of wait and sleep.

The preemptive scheduling model is that many threads are in a runnable state (waiting state), but only one thread is actually running. The thread runs until it terminates into a runnable state (waiting state) or another thread with a higher priority becomes runnable. In the latter case, the bottom priority thread is preempted by the high priority thread, and the high priority thread gets the opportunity to run.

Threads can terminate and enter a runnable state for a variety of reasons (because of congestion).

For example, a thread's code can execute the Thread.sleep () method at the appropriate time, deliberately aborting the thread; the thread may have to wait until the resource is available in order to access the resource.

All runnable threads remain in different pools according to priority. Once the blocked thread enters the runnable state, it will be put back into the appropriate runnable pool. Threads in the non-empty pool with the highest priority will get cpu time.

The last sentence is imprecise because:

(1) in most JVM implementations, although there is no guarantee that priority makes any sense, priority seems to work in a preemptive manner.

(2) Microsoft windows's evaluation affects the behavior of threads, so that although a runnable Java thread with priority 5 is waiting for cpu time, a Java thread with priority 4 may be running.

In fact, many JVM use queues to implement pooling, but there is no guaranteed behavior.

This is the end of the explanation on how to carry out threads. I hope the above content can be of some help to you and can learn more knowledge. If you think the article is good, you can share it for more people to see.

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