您的位置:首页 > 编程语言 > Java开发

(原)测试 Java中Synchronized锁定对象的用法

2016-09-02 14:00 453 查看
今天再android_serial_port中看到了关键字 synchronized;因为刚好在学java和android,所以就查了一下它的用法:

于是把代码中的一小段代码拿了出来,做了一下修改,测试了下,结果出现的情况:

thread1: wait
thread2: notify
thread2:1
thread2: notify
thread2:2
thread2: notify
thread2:3
thread2: notify
thread2:4
thread2: notify
thread2:5
thread2: notify
thread2:6
thread2: notify
thread2:7
thread2: notify
thread2:8
thread2: notify
thread2:9
thread2: notify
thread2:10
thread1:1
thread1: wait
thread1:2
thread1: wait
thread1:3
thread1: wait
thread1:4
thread1: wait
thread1:5
thread1: wait
thread1:6
thread1: wait
thread1:7
thread1: wait
thread1:8
thread1: wait
thread1:9
thread1: wait
thread1:10


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: