zoukankan      html  css  js  c++  java
  • 多线程优先级

    class user extends Thread {
    private Thread fth;

    user(String name, Thread fth) {
    super(name);
    this.fth = fth;
    }

    public void run() {
    System.out.println(this.getName());
    try {
    sleep(2000);
    } catch (Exception e) {
    // TODO: handle exception
    throw new RuntimeException(e);
    }
    if (fth != null) {
    try {
    fth.join();

    } catch (Exception e) {

    }
    System.out.println("NAME:" + this.getName() + "Bye");

    }
    }


    }

    class MT{
    public static void main(String[] args) throws InterruptedException {
    user u1=new user("1",null);
    user u2=new user("2",u1);
    user u3=new user("3",u2);
    user u4=new user("4",u3);
    u1.setPriority(Thread.MAX_PRIORITY);
    u2.setPriority(Thread.MAX_PRIORITY-1);
    u3.setPriority(Thread.MAX_PRIORITY-2);
    u4.setPriority(Thread.MAX_PRIORITY-3);
    u1.start();
    u2.start();
    u3.start();
    u4.start();

    }
    }

  • 相关阅读:
    spoj705
    bzoj2440
    spoj220
    bzoj2301
    hdu1695
    poj3294
    hdu3518
    poj3693
    函数
    样式
  • 原文地址:https://www.cnblogs.com/sunshine-in/p/4087537.html
Copyright © 2011-2022 走看看