服务热线:13616026886

技术文档 欢迎使用技术文档,我们为你提供从新手到专业开发者的所有资源,你也可以通过它日益精进

位置:首页 > 技术文档 > JAVA > 新手入门 > 基础入门 > 查看文档

[java100例]067、线程优先级

import java.util.*;
/**
 * <p>title: 提高线程优先级</p>
 * <p>description: 通过修改线程的优先级,是线程获得优先处理。</p>
 * <p>copyright: copyright (c) 2003</p>
 * <p>filename: upprithread.java</p>
 * @version 1.0
 */
public class upprithread {
 //主方法
 public static void main(string[] args) throws exception {
  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);
 }
 //类说明:线程1,不更改优先级
 static class thread1 extends thread {
  public void run(){
   while(true){
    try {
     thread.sleep(100);
     }
    catch (exception e){
     e.printstacktrace();
     }
     system.out.println("我是线程111");
    }
   }
  }
 //类说明:线程2,提高优先级
 static class thread2 extends thread {


  public void run(){
   while(true){
    try {
     thread.sleep(100);
     }
    catch (exception e){
     e.printstacktrace();
     }
     system.out.println("我是线程222.........................");
    }
   }
 }
}

扫描关注微信公众号