![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
JAVA
杜子麟
喜欢编程。看好安卓!
展开
-
volatile关键字
public class Main3 { public static void main(String[] args) { MyRunable runable = new MyRunable(); Thread thread = new Thread(runable); thread.start(); try { ...原创 2018-12-12 17:02:17 · 128 阅读 · 0 评论 -
JAVA多线程 join()方法
有时子线程中会做大量耗时运算,而主线程可能结束可能早于子线程,我们希望子线程结束后主线程再结束,我们就可使用join方法 例如原来的代码是这样的: public class Main6 { public static void main(String[] args) { Thread6 thread6 = new Thread6(); thread6....原创 2018-12-13 14:43:38 · 132 阅读 · 0 评论 -
JAVA同步Lock之ReentrantLock类简单使用
public class Main7 { public static void main(String[] args) { Lock lock = new ReentrantLock(); Thread7 threadA = new Thread7(lock); threadA.setName("A"); Thread7 ...原创 2018-12-13 16:01:11 · 216 阅读 · 0 评论 -
使用Condition来实现等待/通知
使用Condition来实现wait()和notify() public class Main8 { public static void main(String[] args) { Lock lock = new ReentrantLock(); MyService service = new MyService(lock); new...原创 2018-12-13 16:21:25 · 238 阅读 · 0 评论 -
Rxjava2切换线程原理
版本如下: implementation "io.reactivex.rxjava2:rxjava:2.2.5" implementation 'io.reactivex.rxjava2:rxandroid:2.1.0' 建议一边看博客,一边打开Android studio看代码 首先分析 AndroidSchedulers.mainThread() ,后面分析Schedu...原创 2019-01-11 16:48:09 · 731 阅读 · 0 评论