07 2017 档案
摘要:众所周知,无限制下多线程操作共享变量是危险的,为了保证线程安全语义,一般的建议是在操作共享变量时加锁,比方说在用synchronized关键字修饰的方法内读写共享变量。 但是synchronized开销较大,有没有更轻量更优雅的解决方案呢? volatile是轻量级的synchronized,在正确
阅读全文
摘要:基于版本jdk1.7.0_80 java.util.concurrent.locks.ReentrantReadWriteLock 代码如下 /* * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * * * *
阅读全文
摘要:基于版本jdk1.7.0_80 java.util.concurrent.FutureTask 代码如下 /* * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * * * * * * * * * * * * *
阅读全文
摘要:基于版本jdk1.7.0_80 java.util.concurrent.CopyOnWriteArrayList 代码如下 /* * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. * ORA
阅读全文
摘要:基于版本jdk1.7.0_80 java.util.concurrent.ScheduledThreadPoolExecutor 代码如下 /* * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * * * * *
阅读全文
摘要:基于版本jdk1.7.0_80 java.util.concurrent.ThreadPoolExecutor 代码如下 /* * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * * * * * * * * *
阅读全文
摘要:基于版本jdk1.7.0_80 java.util.concurrent.ConcurrentHashMap 代码如下 /* * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * * * * * * * * * *
阅读全文
摘要:基于版本jdk1.7.0_80 java.util.concurrent.DelayQueue 代码如下 /* * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * * * * * * * * * * * * *
阅读全文
摘要:基于版本jdk1.7.0_80 java.util.concurrent.ConcurrentLinkedQueue 代码如下 /* * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * * * * * * * *
阅读全文
摘要:基于版本jdk1.7.0_80 java.util.concurrent.LinkedBlockingQueue 代码如下 /* * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * * * * * * * * *
阅读全文
摘要:基于版本jdk1.7.0_80 java.util.concurrent.ArrayBlockingQueue 代码如下 /* * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * * * * * * * * *
阅读全文
摘要:基于版本jdk1.7.0_80 java.util.concurrent.locks.AbstractQueuedSynchronizer.ConditionObject 代码如下 /** * Condition implementation for a {@link * AbstractQueue
阅读全文
摘要:基于版本jdk1.7.0_80 java.util.concurrent.CyclicBarrier 代码如下 /* * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * * * * * * * * * * * *
阅读全文
摘要:基于版本jdk1.7.0_80 java.util.concurrent.Semaphore 代码如下 /* * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * * * * * * * * * * * * * *
阅读全文
摘要:基于版本jdk1.7.0_80 java.util.concurrent.CountDownLatch 代码如下 /* * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * * * * * * * * * * *
阅读全文
摘要:基于版本jdk1.7.0_80 java.util.concurrent.locks.ReentrantLock 代码如下 /* * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * * * * * * * * *
阅读全文
摘要:基于版本jdk1.7.0_80 java.util.concurrent.locks.AbstractQueuedSynchronizer 代码如下 /* * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * *
阅读全文
摘要:如果不用OS提供的mutex,我们该如何实现互斥锁?(不考虑重入的情况) 1. naive lock 最简单的想法是,搞一个volatile类型的共享变量flag,值可以是flase(无锁)或者true(有锁),竞争线程监听flag,一旦发现flag为false,那么尝试cas更新flag为true
阅读全文
摘要:基于版本jdk1.7.0_80 java.util.concurrent.atomic.AtomicInteger 代码如下 /* * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * * * * * * * *
阅读全文
摘要:Java集合框架 JDK7集合框架源码阅读(一) ArrayList JDK7集合框架源码阅读(二) LinkedList JDK7集合框架源码阅读(三) HashMap JDK7集合框架源码阅读(四) LinkedHashMap JDK7集合框架源码阅读(五) Hashtable JDK7集合框架
阅读全文
摘要:基于版本jdk1.7.0_80 java.util.ArrayDeque 代码如下 /* * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * * * * * * * * * * * * * * * * * * *
阅读全文
摘要:基于版本jdk1.7.0_80 java.util.HashSet java.util.LinkedHashSet 代码如下 HashSet,312行 /* * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights re
阅读全文
摘要:基于版本jdk1.7.0_80 java.util.Hashtable 代码如下 /* * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved. * ORACLE PROPRIETARY/CONFID
阅读全文
摘要:基于版本jdk1.7.0_80 java.util.LinkedHashMap 代码如下 /* * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. * ORACLE PROPRIETARY/CO
阅读全文
摘要:基于版本jdk1.7.0_80 java.util.HashMap 代码如下 /* * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. * ORACLE PROPRIETARY/CONFIDEN
阅读全文
摘要:基于版本jdk1.7.0_80 java.util.LinkedList 代码如下 /* * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. * ORACLE PROPRIETARY/CONFI
阅读全文
摘要:基于版本jdk1.7.0_80 java.util.ArrayList 代码如下 /* * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. * ORACLE PROPRIETARY/CONFID
阅读全文