锁
大风起曦云飞扬
我曾经翻过山和大海,也越过人山人海...
展开
-
Java Lock Condition 生产者消费者模式示例
package test; import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; public class LockTest { public static void main(...原创 2020-05-01 22:57:39 · 109 阅读 · 0 评论 -
Java 生产者消费者模式示例
package test; public class 生产者消费者示例 { public static void main(String[] args) { Res r = new Res("面包"); Productor p = new Productor(r); Customer c = new Customer(r); Thread t1 = new Thread(p)...原创 2020-05-01 16:25:58 · 155 阅读 · 0 评论 -
Java 多线程,wait()和notify()方法示例
package test; public class Thread_Wait_Notify { public static void main(String[] args) { test(); } private static void test() { Resource r = new Resource(); In in = new In(r); Out out = ...原创 2020-04-30 17:52:44 · 119 阅读 · 0 评论 -
Java 死锁示例
package ztest; public class 死锁 { public static void main(String[] args) { MyThread mt1 = new MyThread(true); MyThread mt2 = new MyThread(false); Thread t1 = new Thread(mt1); Thread t2 = new...原创 2020-04-28 23:25:26 · 99 阅读 · 0 评论 -
Java 单例模式:懒汉式、饿汉式
package ztest; public class 单例 { public static void main(String[] args) { Single s1 = Single.getInstance(); Single s2 = Single.getInstance(); System.out.println(s1 == s2); } } //懒汉式 class Si...原创 2020-04-28 22:31:05 · 89 阅读 · 0 评论