![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
多线程
青年卫大师
这个作者很懒,什么都没留下…
展开
-
synchronized
synchronized下面两种写法是等效的 推荐使用t2 尽量锁住最小的同步单位 synchronized void t(){ } void t2(){ synchronized(this){ }}这两种也是等效的 static synchronized void t(){ } static void t1()原创 2017-11-07 13:30:57 · 226 阅读 · 0 评论 -
volatile关键字的测试
public class VolatileTest { volatile int x = 1; Executor executor = Executors.newFixedThreadPool(4); public static void main(String[] args) { new VolatileTest().run(); } void run(){ ex原创 2017-10-11 14:27:06 · 676 阅读 · 1 评论 -
ThreadLocal 及其应用
public class SyncSimpleDateFormat extends SimpleDateFormat { /** * * */ private static final long serialVersionUID = 1L; private ThreadLocal local = new ThreadLocal(); private String patte原创 2017-10-11 15:47:59 · 287 阅读 · 0 评论 -
ReadWriteLock 读写锁测试
static final ReadWriteLock lock = new ReentrantReadWriteLock(true); static Executor executor = Executors.newFixedThreadPool(4); public static void main(String[] args) { //创建双读双写的线程 executor.exe原创 2017-10-12 16:32:28 · 749 阅读 · 0 评论 -
使用lock 产生死锁
public void lock(){ final Lock lock1 = new ReentrantLock(); final Lock lock2 = new ReentrantLock(); Executor executor = Executors.newFixedThreadPool(2); executor.execute(new Runnable() { pu原创 2017-10-12 16:56:44 · 1383 阅读 · 0 评论 -
使用synchronized产生死锁
public void sync() { final Object object1 = new Object(); final Object object2 = new Object(); Executor executor = Executors.newFixedThreadPool(2); executor.execute(new Runnable() { public原创 2017-10-12 17:09:13 · 1622 阅读 · 0 评论