随笔分类 - 多线程
摘要:创建线程及启动的几种方式 public class ThreadNew { public static void main(String[] args) { new MyThread1().start(); new Thread(new MyThread2()).start(); FutureTas
阅读全文
摘要:生产者消费者模式2-->信号灯法 public class TestPC2 { public static void main(String[] args) { TV tv = new TV(); new Player(tv).start(); new Watcher(tv).start(); }
阅读全文
摘要:生产者消费者模式-->管程法 public class TestPC { public static void main(String[] args) { SynContainer container = new SynContainer(); new Productor(container).st
阅读全文
摘要:Lock锁 public class TestLock { public static void main(String[] args) { Test t1 = new Test(); new Thread(t1).start(); new Thread(t1).start(); new Threa
阅读全文
摘要:死锁 public class DeadLock { public static void main(String[] args) { MakeUp g1 = new MakeUp(0, "小红"); MakeUp g2 = new MakeUp(1, "小绿"); g1.start(); g2.s
阅读全文
摘要:线程优先级 public class TestPriority { public static void main(String[] args) { System.out.println(Thread.currentThread().getName()+" >"+Thread.currentThre
阅读全文
摘要:观测线程状态 public class TestState { public static void main(String[] args) throws InterruptedException { Thread thread = new Thread(()->{ for (int i = 0;
阅读全文
摘要:线程停止 public class TestStop implements Runnable { //1.设置一个标志位 private boolean flag = true; @Override public void run() { int i = 0; while (flag){ Syste
阅读全文
摘要:lambda表达式: //推导lambda表达式 public class TestLambda { //静态内部类 static class Like2 implements ILike{ @Override public void lambda() { System.out.println("I
阅读全文
摘要:多线程 一、创建多线程的几种方式 继承Thread类 实现runable接口 实现callable接口 *注意:*当创建一个线程后,调用的是start方法,会优先走主线程main;当调用的是run方法时,优先走run方法。线程的执行是CPU调度安排,故可能每次执行都不一样。 使用comments-i
阅读全文
浙公网安备 33010602011771号