
并发
knife1220
这个作者很懒,什么都没留下…
展开
-
java futuretask的基本应用
public static void main(String args[]) throws InterruptedException, ExecutionException { Callable<String> c=new Callable<String>() { @Override public String call() throws Exce...原创 2019-01-07 16:04:53 · 328 阅读 · 1 评论 -
CountDownLatch CyclicBarrier 和Semaphore
1.CountDownLatch public static void main(String args[]) { final CountDownLatch start=new CountDownLatch(1); final CountDownLatch end=new CountDownLatch(10); for(int i=0;i<10;i++) { ...原创 2019-01-03 18:24:01 · 206 阅读 · 0 评论 -
java lock四种用法
1.普通用法public static void testlock() { Lock lock = new ReentrantLock(); Thread t = new Thread(new Runnable() { @Override public void run() { // TODO Auto-generated method stub loc...原创 2018-12-27 16:37:34 · 21840 阅读 · 6 评论 -
java volatile 的两种应用场景
1.可见性static class demoThread implements Runnable{ private boolean flag=false; @Override public void run() { // TODO Auto-generated method stub try { Thread.sleep(100); } cat...原创 2018-12-27 13:13:38 · 208 阅读 · 0 评论 -
ReentrantLock 原理分析
1.lock public void lock() { sync.lock(); }这是lock的源码,调用的其实是sync这个对象的lock函数,而sync是ReentrantLock内部类Sync的一个对象实例,他有两种实现NonfairSync(非公平锁)和FairSync(公平锁)先看公平锁的lock函数final void lock() { ...原创 2019-01-21 11:03:10 · 187 阅读 · 0 评论 -
ThreadPoolExecutor 源码分析
1.构造函数public ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, ...原创 2019-01-21 15:31:28 · 149 阅读 · 0 评论