原创 

java小代码:java线程的一些基本属性使用

分类:    438人阅读    IT小君  2017-10-19 22:02
package mutilThreadDemo;

/**
 * Hello world!
 ** **app:** java线程的一些基本属性使用
 */
public class App 
{
    public static void main( String[] args ) throws Exception
    {
        System.out.println("虚拟机内核数:"+Runtime.getRuntime().availableProcessors());
        Runnable r = ()->{
            Thread th = Thread.currentThread();
            System.out.printf("我是:%s,我的id:%s,我的优先级:%s,是否存活:%s,当前状态:%sn",
                    th.getName(),th.getId(),th.getPriority(),th.isAlive(),th.getState());
        };
        Thread th1 = new Thread(r,"线程1号");
        Thread th2 = new Thread(r,"线程2号");
        th1.start();
        th2.start();

        Thread.sleep(1000);
    }
}
支付宝打赏 微信打赏

如果文章对你有帮助,欢迎点击上方按钮打赏作者

 工具推荐 更多»