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

     1 class MyThread implements Runnable{
    2 public void run(){
    3 for(int i=0;i<5;i++){
    4 try {
    5 Thread.sleep(500);
    6 } catch (Exception e){
    7 }
    8 System.out.println(Thread.currentThread().getName()+"运行,i="+i);
    9 }
    10 }
    11 }
    12 public class ThreadDemo {
    13 public static void main(String[] args) {
    14 Thread t1=new Thread(new MyThread(),"线程A");
    15 Thread t2=new Thread(new MyThread(),"线程B");
    16 Thread t3=new Thread(new MyThread(),"线程C");
    17 t1.setPriority(Thread.MIN_PRIORITY);
    18 t2.setPriority(Thread.MAX_PRIORITY);
    19 t3.setPriority(Thread.NORM_PRIORITY);
    20 t1.start();
    21 t2.start();
    22 t3.start();
    23
    24 }
    25 }
    26

    线程的优先级越高不一定会先执行,而由其CPU的调度决定。。。

  • 相关阅读:
    linux防火墙iptables
    etc/fstab
    EDT改成CST
    echo
    dd
    chown
    CAT
    Linux grep
    CHECKSUM比较两表字段值差异
    通过GitHub部署项目到Nginx服务器
  • 原文地址:https://www.cnblogs.com/dennisac/p/2392356.html
Copyright © 2011-2022 走看看