随笔分类 -  多线程

摘要:创建线程及启动的几种方式 public class ThreadNew { public static void main(String[] args) { new MyThread1().start(); new Thread(new MyThread2()).start(); FutureTas 阅读全文
posted @ 2020-06-26 22:43 小徐学狂 阅读(219) 评论(0) 推荐(0)
摘要:生产者消费者模式2-->信号灯法 public class TestPC2 { public static void main(String[] args) { TV tv = new TV(); new Player(tv).start(); new Watcher(tv).start(); } 阅读全文
posted @ 2020-06-26 20:30 小徐学狂 阅读(194) 评论(0) 推荐(0)
摘要:生产者消费者模式-->管程法 public class TestPC { public static void main(String[] args) { SynContainer container = new SynContainer(); new Productor(container).st 阅读全文
posted @ 2020-06-26 18:05 小徐学狂 阅读(169) 评论(0) 推荐(0)
摘要:Lock锁 public class TestLock { public static void main(String[] args) { Test t1 = new Test(); new Thread(t1).start(); new Thread(t1).start(); new Threa 阅读全文
posted @ 2020-06-26 11:01 小徐学狂 阅读(229) 评论(0) 推荐(0)
摘要:死锁 public class DeadLock { public static void main(String[] args) { MakeUp g1 = new MakeUp(0, "小红"); MakeUp g2 = new MakeUp(1, "小绿"); g1.start(); g2.s 阅读全文
posted @ 2020-06-26 10:23 小徐学狂 阅读(113) 评论(0) 推荐(0)
摘要:线程优先级 public class TestPriority { public static void main(String[] args) { System.out.println(Thread.currentThread().getName()+" >"+Thread.currentThre 阅读全文
posted @ 2020-06-22 16:09 小徐学狂 阅读(324) 评论(0) 推荐(0)
摘要:观测线程状态 public class TestState { public static void main(String[] args) throws InterruptedException { Thread thread = new Thread(()->{ for (int i = 0; 阅读全文
posted @ 2020-06-19 15:13 小徐学狂 阅读(143) 评论(0) 推荐(0)
摘要:线程停止 public class TestStop implements Runnable { //1.设置一个标志位 private boolean flag = true; @Override public void run() { int i = 0; while (flag){ Syste 阅读全文
posted @ 2020-06-19 15:12 小徐学狂 阅读(163) 评论(0) 推荐(0)
摘要:lambda表达式: //推导lambda表达式 public class TestLambda { //静态内部类 static class Like2 implements ILike{ @Override public void lambda() { System.out.println("I 阅读全文
posted @ 2020-06-05 10:42 小徐学狂 阅读(193) 评论(0) 推荐(0)
摘要:多线程 一、创建多线程的几种方式 继承Thread类 实现runable接口 实现callable接口 *注意:*当创建一个线程后,调用的是start方法,会优先走主线程main;当调用的是run方法时,优先走run方法。线程的执行是CPU调度安排,故可能每次执行都不一样。 使用comments-i 阅读全文
posted @ 2020-06-03 17:35 小徐学狂 阅读(256) 评论(0) 推荐(0)