Limitations of Java multithreaded Programming-priority _JSP programming

Source: Internet
Author: User
Restricting thread precedence and scheduling

The Java threading model involves the thread priority that can be changed dynamically. In essence, a thread's priority is a number from 1 to 10, and the larger the number, the more urgent the task is. The JVM standard first invokes a higher-priority thread before calling a lower-priority thread. However, the standard is random for handling threads that have the same priority. How these threads are handled depends on the base-level operating system policy. In some cases, threads with the same priority are run at time-sharing, and in other cases the thread runs to the end. Keep in mind that Java supports 10 priorities, and the grassroots operating system supports a much lower priority, which can create some confusion. Therefore, you can only use priority as a very crude tool. The final control can be accomplished by judicious use of the yield () function. In general, do not rely on thread precedence to control the state of a thread.

   Summary

This article describes how to use threads in Java programs. The more important question, like whether threading should be used, depends heavily on the application at hand. One way to decide whether to use multithreading in your application is to estimate the amount of code that can run in parallel. And keep the following points in mind:

Using multithreading does not increase the CPU's ability. However, if the local thread of the JVM is implemented, the different threads can be run concurrently on different processors (in a multiprocessor machine), making the multiple CPU machines fully leveraged.

If the application is computationally intensive and is constrained by CPU functionality, only a multiple-CPU machine can benefit from more threads.

Multithreading is usually advantageous when an application must wait for slow resources, such as a network connection or a database connection, or when the application is non-interactive.

Internet-based software is necessary to be multi-threaded, otherwise the user will feel the application is slow to reflect. For example, multithreading can make programming easier when developing servers that support a large number of clients. In this case, each thread can serve a different customer or customer group, which shortens the response time.

Some programmers may have used threads in C and other languages where there is no language support for threads in those languages. These programmers are likely to get lost in the thread of confidence.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.