Java多线程中使用synchronized说明

上传:chenxia67010 浏览: 17 推荐: 0 文件:PDF 大小:26.37KB 上传时间:2020-12-31 00:13:48 版权申诉
1.在类中方法上加上 synchronized关键字,是对整个对象加锁,当一个线程访问带有synchronized的方法时,其他带有synchronized的方法的访问都会阻塞。 样例: public class ThreadTest { public static void main(String[] args) { Stu stu = new Stu(); StuThread1 t1 = new StuThread1(stu); t1.start(); StuThread2 t2 = new StuTh
上传资源
用户评论