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

    可以用setPriority来设置线程的优先级,getPriority取得线程的优先级:

     1 package priority;
     2 
     3 import sharevar.Machine;
     4 
     5 public class priority extends Thread {
     6     private static StringBuffer log=new StringBuffer();
     7     private static int count=0;
     8     
     9     public void run() {
    10         for (int a=0;a<20;a++) {
    11             log.append(currentThread().getName()+":"+a);
    12             if (++count %10==0) log.append("\n");
    13         }
    14     }
    15 
    16     /**
    17      * @param args
    18      */
    19     public static void main(String[] args) {
    20         // TODO Auto-generated method stub
    21         Machine m1=new Machine();
    22         Machine m2=new Machine();
    23         m1.setName("m1");
    24         m2.setName("m2");
    25         
    26         Thread main=Thread.currentThread();   //获得主线程
    27         //查看和设置线程的优先级
    28         System.out.println("default priority of main:"+main.getPriority());
    29         //打印m2线程默认优先级
    30         System.out.println("default priority of m1:"+m1.getPriority());
    31         //打印m2线程默认优先级
    32         System.out.println("default priority of m2:"+m2.getPriority());
    33         
    34         m2.setPriority(Thread.MAX_PRIORITY);
    35         m1.setPriority(Thread.MIN_PRIORITY);
    36         
    37         m1.start();
    38         m2.start();
    39         System.out.println(log);
    40     }
    41 
    42 }
  • 相关阅读:
    二维卷积层
    gluon 实现多层感知机MLP分类FashionMNIST
    gluon实现softmax分类FashionMNIST
    gluon 实现线性回归
    GPU使用
    Python迭代器和生成器
    L2范数惩罚项,高维线性回归
    多项式拟合
    模型选择,欠拟合,过拟合
    多层感知机MLP的gluon版分类minist
  • 原文地址:https://www.cnblogs.com/djcsch2001/p/2486622.html
Copyright © 2011-2022 走看看