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