摘要:
线程池的大小对系统的性能有一定的影响。过大或者过小的线程数量都无法发挥到最优的系统性能。只要避免线程池的过大或者过小,那么一把来说线程池对系统的性能影响不大。我经常参考的线程池大小的经验公式: Ncpu=CPU的数量 Ucpu=目标CPU的使用率,0<= Ucpu<=1 W/C=等待的时间与计算的时 阅读全文
摘要:
参数说明:public ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue) { this(cor 阅读全文
摘要:
package 第三章.线程阻塞工具LockSupport;import java.util.concurrent.locks.LockSupport;/** * Created by zzq on 2018/2/2. */public class LockSupportDemo { public 阅读全文
摘要:
package 第三章.循环栅栏CyclicBarrier;import java.util.concurrent.BrokenBarrierException;import java.util.concurrent.CyclicBarrier;/** * Created by zzq on 201 阅读全文
摘要:
一、分为两种:公平和非公平线程 a b c d e公平:按顺序执行:a,b,d,e 读锁 c 写锁 1.a,b 执行 c 堵塞,d,e 等待 2.a,b执行结束 c获取锁 d,e堵塞等待 3.c执行结束 d开始执行,然后在唤醒e非公平: 1,2步骤相同 3,c执行结束的时候,新来个线程 f读锁,在d 阅读全文
摘要:
package 第三章.倒计时器CountDownLatch;import java.util.concurrent.CountDownLatch;/** * Created by zzq on 2018/1/24. */public class CountDoenLatchTest impleme 阅读全文
摘要:
package 第三章.信号量;import java.util.concurrent.ExecutorService;import java.util.concurrent.Executors;import java.util.concurrent.Semaphore;/** * Created 阅读全文
摘要:
package 第三章.重入锁;import java.util.concurrent.locks.Condition;import java.util.concurrent.locks.ReentrantLock;/** * Created by zzq on 2018/1/23. */publi 阅读全文
摘要:
package 第三章.重入锁;import java.util.concurrent.locks.ReentrantLock;/** * Created by zzq on 2018/1/22. */public class ReentrantLockTest implements Runnabl 阅读全文
摘要:
package 第二章.错误的加锁;/** * Created by zzq on 2018/1/22. */public class BadLockOnInteger implements Runnable{ public static Integer i = 0; static BadLockO 阅读全文