2021年3月7日
摘要: 守护线程daemon 线程分为用户线程(正常都是用户线程)和守护线程。 虚拟机要等用户线程,不等守护线程。 setDaemon是boolean值,默认是false public class TestThreadDaemon { public static void main(String[] arg 阅读全文
posted @ 2021-03-07 22:38 要给小八赚罐头钱 阅读(34) 评论(0) 推荐(0)
摘要: public class TestThreadPriority { public static void main(String[] args) { System.out.println(Thread.currentThread().getName()+"-->的优先级是"+Thread.curre 阅读全文
posted @ 2021-03-07 21:58 要给小八赚罐头钱 阅读(56) 评论(0) 推荐(0)
摘要: 线程状态 thread.getState() Thread.State.TERMINATED public class TestThreadState{ public static void main(String[] args) { Thread thread = new Thread(()->{ 阅读全文
posted @ 2021-03-07 21:40 要给小八赚罐头钱 阅读(187) 评论(0) 推荐(0)
摘要: 线程强制执行 join public class TestJoin implements Runnable{ @Override public void run() { for (int i = 0; i < 100; i++) { System.out.println("靠边!俺来了!"+i); 阅读全文
posted @ 2021-03-07 16:53 要给小八赚罐头钱 阅读(14) 评论(0) 推荐(0)
摘要: 线程礼让yield 礼让不一定成功哦~ public class TestYield { public static void main(String[] args) { Yield yield = new Yield();​ new Thread(yield,"A").start(); new T 阅读全文
posted @ 2021-03-07 16:31 要给小八赚罐头钱 阅读(31) 评论(0) 推荐(0)
摘要: 模拟打印当前时间 import java.text.SimpleDateFormat;import java.util.Date;​public class TestThreadSleep implements Runnable{ private boolean flag=true; @Overri 阅读全文
posted @ 2021-03-07 16:19 要给小八赚罐头钱 阅读(69) 评论(0) 推荐(0)
摘要: 线程停止 不要用自带的stop方法,设置flag标志位停止线程。 public class TestThreadStop implements Runnable{ private boolean flag=true; @Override public void run() { int i=0; wh 阅读全文
posted @ 2021-03-07 15:34 要给小八赚罐头钱 阅读(39) 评论(0) 推荐(0)