Java multi-threaded programming combat essence of the restrictions priority
Restrictions thread priorities and scheduling
Java threading model involving dynamic changes can thread priority. Essentially, the priority of threads from 1-10 among a number, the larger the number that the task becomes more urgent. JVM standard first call of high-priority threads, before calling a lower priority thread. However, the standards have the same priority thread processing is random. How to deal with these threads depends on the grass-roots level operating system strategy. In some cases, the priority the same time of the threads running in the other cases, the thread will always run to the end. Remember, Java support 10 priority, grass-roots support for the operating system may have to be the priority of much smaller, it would cause some confusion. Therefore, priority will be only as a very rough instrument. Finally control through wise use of yield () function to complete. Under normal circumstances, please do not rely on the thread priority to control the thread state.
Summary
This article illustrates the process of how the use of Java threads. Thread like whether we should use this more important issue in the very process depends on the application at hand. Decide whether or not the application of the use of multi-threading method is, it is estimated that the code can be run in parallel. And remember the following points:
Multithreading will not increase the use of CPU capacity. However, if the use of local JVM thread fulfilled, the threads can be different in different processors running at the same time (multi-CPU machines), so that multi-CPU machines are fully utilized.
If your application is compute-intensive, and the function of the CPU constraints, the only multi-CPU machines from the more threads can benefit.
When the application must wait for the slow resources (such as network connections or database connection), or when the application of non-interactive, multi-threading is usually beneficial.
Internet-based software is necessary is a multi-thread, otherwise, users will be feeling applications reflect slow. For example, when a large number of customers to support the development of the server, multi-threaded programming can more easily. In such circumstances, each thread can be for different customers or customer group, so as to shorten the response time.
Some programmers may be in C and other languages used in the thread, the thread in those languages have no language support. These programmers may usually be on the threads do lose confidence.
Tags: java programming ideas






