Android (Java) Learning Note 63: Scheduling of threads

Source: Internet
Author: User

1  Packagecn.itcast_04;2 3 /*4 * Our thread does not have a priority, there must be a default priority. 5 * So, what is the default priority?6 * How do I get the priority of a thread object?7 * Public final int getpriority (): Returns the priority of the thread object8 * How do I prioritize thread objects?9 * Public final void setpriority (int newpriority): Change the priority of the thread. Ten  *  One * Note: A * Thread default priority is 5.  - * The range of thread priority is: 1-10.  - * High Thread priority only indicates a high probability of the CPU time slices obtained by the thread, but only when the number of times is higher, or multiple runs, can you see a better effect.  the  *          - * illegalargumentexception: illegal parameter exception.  - * Throws an exception indicating that an invalid or incorrect parameter was passed to the method.  -  *  +  */ -  Public classThreadprioritydemo { +      Public Static voidMain (string[] args) { AThreadPriority TP1 =Newthreadpriority (); atThreadPriority TP2 =Newthreadpriority (); -ThreadPriority TP3 =Newthreadpriority (); -  -Tp1.setname ("Oriental Undefeated")); -Tp2.setname ("Yue Qun"); -Tp3.setname ("林平"); in  -         //get the default priority level to         //System.out.println (Tp1.getpriority ()); +         //System.out.println (Tp2.getpriority ()); -         //System.out.println (Tp3.getpriority ()); the  *         //Set Thread Priority $         //tp1.setpriority (100000);Panax Notoginseng          -         //set the correct thread priority, TP3 is not set here, indicating the default setting TP3 = 5 theTp1.setpriority (10); +Tp2.setpriority (1); A  the Tp1.start (); + Tp2.start (); - Tp3.start (); $     } $}

Android (Java) Learning Note 63: Scheduling of threads

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.