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
  • 相关阅读:
    配置Kickstart无人值守安装centos5.9 天高地厚
    数据库是什么,它是做什么用的? 天高地厚
    Mysql主从复制 天高地厚
    android开发中eclipse里xml的自动提示
    "error: device not found" and "error:device offline"
    gentoo中emerge失效:File "/usr/bin/emerge", line 43
    android:修改preference中view属性
    gerrit上利用sshkeygen公钥
    git 基本命令介绍
    prebuilt/linuxx86/toolchain/armeabi4.4.3/bin/armeabigcc: /lib/libc.so.6: version `GLIBC_2.11' not found:解决办法
  • 原文地址:https://www.cnblogs.com/edison20161121/p/7954800.html
Copyright © 2011-2022 走看看