zoukankan      html  css  js  c++  java
  • 1.10.1优先级具有继承特性

    jdk中有3个常量来定义优先级

    public final static int MIN_PRIOPITY = 1;

    public final static int NORM_PRIOPITY = 5;

    public final static int MAX_PRIOPITY = 10;

    在java中,线程的优先级具有继承性,比如A线程启动B线程,则B线程的优先级和A时一样的

    测试

     1 package com.cky.demo;
     2 
     3 /**
     4  * Created by edison on 2017/12/3.
     5  */
     6 public class MyThread1 extends Thread{
     7     @Override
     8     public void run() {
     9         super.run();
    10         System.out.println("线程1:"+ this.getPriority());
    11         Thread2 thread2 = new Thread2();
    12         thread2.start();
    13     }
    14 }
     1 package com.cky.demo;
     2 
     3 /**
     4  * Created by edison on 2017/12/3.
     5  */
     6 public class Thread2 extends Thread {
     7     @Override
     8     public void run() {
     9         System.out.println("线程2:"+ this.getPriority());
    10     }
    11 }
     1 package com.cky.demo;
     2 
     3 /**
     4  * Created by edison on 2017/12/3.
     5  */
     6 public class TestDemo {
     7     public static void main(String[] args) {
     8         System.out.println("main " + Thread.currentThread().getPriority());
     9         //Thread.currentThread().setPriority(6);
    10         System.out.println("main " + Thread.currentThread().getPriority());
    11         MyThread1 th = new MyThread1();
    12         th.start();
    13     }
    14 }
    C:itsoftjdkinjava -Didea.launcher.port=7539 "-Didea.launcher.bin.path=C:itsoftideaIntelliJ IDEA 2016.3.3in" -Dfile.encoding=UTF-8 -classpath "C:itsoftjdkjrelibcharsets.jar;C:itsoftjdkjrelibdeploy.jar;C:itsoftjdkjrelibextaccess-bridge-32.jar;C:itsoftjdkjrelibextcldrdata.jar;C:itsoftjdkjrelibextdnsns.jar;C:itsoftjdkjrelibextjaccess.jar;C:itsoftjdkjrelibextjfxrt.jar;C:itsoftjdkjrelibextlocaledata.jar;C:itsoftjdkjrelibext
    ashorn.jar;C:itsoftjdkjrelibextsunec.jar;C:itsoftjdkjrelibextsunjce_provider.jar;C:itsoftjdkjrelibextsunmscapi.jar;C:itsoftjdkjrelibextsunpkcs11.jar;C:itsoftjdkjrelibextzipfs.jar;C:itsoftjdkjrelibjavaws.jar;C:itsoftjdkjrelibjce.jar;C:itsoftjdkjrelibjfr.jar;C:itsoftjdkjrelibjfxswt.jar;C:itsoftjdkjrelibjsse.jar;C:itsoftjdkjrelibmanagement-agent.jar;C:itsoftjdkjrelibplugin.jar;C:itsoftjdkjrelib
    esources.jar;C:itsoftjdkjrelib
    t.jar;C:多线程核心技术第一章outproduction第一章;C:itsoftideaIntelliJ IDEA 2016.3.3libidea_rt.jar" com.intellij.rt.execution.application.AppMain com.cky.demo.TestDemo
    main 5
    main 5
    线程1:5
    线程2:5

    当去掉注释

    package com.cky.demo;
    
    /**
     * Created by edison on 2017/12/3.
     */
    public class TestDemo {
        public static void main(String[] args) {
            System.out.println("main " + Thread.currentThread().getPriority());
            Thread.currentThread().setPriority(6);
            System.out.println("main " + Thread.currentThread().getPriority());
            MyThread1 th = new MyThread1();
            th.start();
        }
    }
    main 5
    main 6
    线程1:6
    线程2:6
  • 相关阅读:
    Time Zone 【模拟时区转换】(HDU暑假2018多校第一场)
    HDU 1281 棋盘游戏 【二分图最大匹配】
    Codeforces Round #527 (Div. 3) F. Tree with Maximum Cost 【DFS换根 || 树形dp】
    Codeforces Round #527 (Div. 3) D2. Great Vova Wall (Version 2) 【思维】
    Codeforces Round #527 (Div. 3) D1. Great Vova Wall (Version 1) 【思维】
    Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round 4) C. Connect Three 【模拟】
    Avito Cool Challenge 2018 E. Missing Numbers 【枚举】
    Avito Cool Challenge 2018 C. Colorful Bricks 【排列组合】
    005 如何分析问题框架
    004 如何定义和澄清问题
  • 原文地址:https://www.cnblogs.com/edison20161121/p/7954800.html
Copyright © 2011-2022 走看看