「java线程id」java线程interrupt

博主:adminadmin 2022-12-01 21:50:06 86

今天给各位分享java线程id的知识,其中也会对java线程interrupt进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

Java如何获取正在运行的线程的Id

使用:Thread.currentThread().getName() 就可以了

比如会输出:pool-1-thread-7

java怎么得到当前线程的启动线程id

public class  线程id

{

public static void main(String[] args)

{

System.out.println("\n\t\t==========多线程怎么查看当前线程id==========\n");

init();

}//初始化!

private static void init()

{

for (int i=0;i2 ;i++ )

{

new Thread(new TestRunnable()).start();

}

}

}

class TestRunnable implements Runnable

{

//简单测试直接用了静态,偷懒了!

private static int i=10;

public void run()

{

show();

}

synchronized void show()

{

while(i=1)

System.out.println("当前执行的线程Id是:"+Thread.currentThread().getName()+"----"+i--+"\n");

}

}

java 多线程怎么查看当前线程id

public class  线程id

{

public static void main(String[] args) 

{

System.out.println("\n\t\t==========多线程怎么查看当前线程id==========\n");

init();

}//初始化!

private static void init()

{

for (int i=0;i2 ;i++ )

{

new Thread(new TestRunnable()).start();

}

}

}

class TestRunnable implements Runnable

{

//简单测试直接用了静态,偷懒了!

private static int i=10;

public void run()

{

show();

}

synchronized void show()

{

while(i=1)

System.out.println("当前执行的线程Id是:"+Thread.currentThread().getName()+"----"+i--+"\n");

}

}

java线程id的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java线程interrupt、java线程id的信息别忘了在本站进行查找喔。

The End

发布于:2022-12-01,除非注明,否则均为首码项目网原创文章,转载请注明出处。