[JAVA100 example]067, thread priority

Source: Internet
Author: User
Tags sleep static class

import java.util.*
/**
* <p>title: Increase thread priority </p>
* <p>description: By modifying the priority of the thread, Is the thread is given priority. </p>
* <p>copyright:copyright (c) 2003</p>
* <p>Filename:upPRIThread.java</p>
* @version 1.0
*/
public class Upprithread {
//Main method
public static void Main (string[] args) throws  ption {
Thread1 t1 = new Thread1 ();
T1.start ();
Thread2 t2 = new Thread2 ();
T2.start ();
T1.setpriority (thread.min_priority);
T2.setpriority (thread.min_priority);
New Thread (). Sleep (105);
T2.setpriority (thread.max_priority);
New Thread (). Sleep (10500);
}
//Class Description: Thread 1, do not change precedence
Static class Thread1 extends Thread {
public void run () {
while (true) {
Try {
Thread.Sleep (100);   
}
catch (Exception e) {
E.printstacktrace ();

System.out.println ("I am thread 111");
}
}
}
///Class Description: Thread 2, increasing priority
Static class Thread2 extends ThRead {

public void Run () {
while (true) {
try {
Thread.Sleep (MB);
  
catch (Exception e) {
E.printstacktrace ();
The
System.out.println ("I am a thread 222 ... .... ...");;......
}
}
}
}

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.