上一页 1 ··· 7 8 9 10 11 12 13 14 15 ··· 23 下一页
摘要: 1.线程池的状态常量,这里只详细分析其中一个,其他类同,这里看RUNNING状态: // -1的补码为:111-11111111111111111111111111111 // 左移29位后:111-00000000000000000000000000000 // 10进制值为:-536870912 阅读全文
posted @ 2020-09-02 15:55 小窝蜗 阅读(304) 评论(0) 推荐(0)
摘要: byte: byte数据类型是8位、有符号的,以二进制补码表示的整数;(256个数字),占1字节 最小值是-128(-2^7); 最大值是127(2^7-1); 默认值是0; byte类型用在大型数组中节约空间,主要代替整数,因为byte变量占用的空间只有int类型的四分之一; 例子:byte a 阅读全文
posted @ 2020-09-02 11:25 小窝蜗 阅读(209) 评论(0) 推荐(0)
摘要: 1.状态控制 状态控制主要围绕原子整型成员变量ctl: private final AtomicInteger ctl = new AtomicInteger(ctlOf(RUNNING, 0)); private static final int COUNT_BITS = Integer.SIZE 阅读全文
posted @ 2020-09-02 11:08 小窝蜗 阅读(261) 评论(0) 推荐(0)
摘要: 1.设计者(Doug Lea) 2.ThreadPoolExecutor实现的最顶层接口 public interface Executor { void execute(Runnable command); } 说明:ExecutorService提供了很多扩展方法底层基本上是基于Executor 阅读全文
posted @ 2020-09-02 10:22 小窝蜗 阅读(200) 评论(0) 推荐(0)
摘要: public class CASLock { //AtomicInteger是引用类型,final保证堆内存中地址不变,不保证栈内存中引用不改变 private final AtomicInteger value= new AtomicInteger(0); //持有锁的线程才有权限解锁 priva 阅读全文
posted @ 2020-09-01 16:39 小窝蜗 阅读(182) 评论(0) 推荐(0)
摘要: 源码: public final boolean tryAcquireSharedNanos(int arg, long nanosTimeout) throws InterruptedException { if (Thread.interrupted()) throw new Interrupt 阅读全文
posted @ 2020-09-01 16:34 小窝蜗 阅读(93) 评论(0) 推荐(0)
摘要: 1.介绍 基于AQS实现同步器, CountDownLatch 用同步状态持有当前计数, countDown方法调用 release从而导致计数器递减; 当计数器为0时,解除所有线程的等待; await调用acquire,如果计数器为0,acquire 会立即返回,否则阻塞。 通常用于某任务需要等待 阅读全文
posted @ 2020-09-01 16:24 小窝蜗 阅读(196) 评论(0) 推荐(0)
摘要: 1.方法入口: public final void acquireShared(int arg) { if (tryAcquireShared(arg) < 0) doAcquireShared(arg); } 执行tryAcquireShared方法获取资源,若获取成功则直接返回,若失败, 则进入 阅读全文
posted @ 2020-09-01 15:55 小窝蜗 阅读(194) 评论(0) 推荐(0)
摘要: 1.unparkSuccessor(Node) 该方法主要用于唤醒等待队列中的下一个阻塞线程。 private void unparkSuccessor(Node node) { // 获取当前节点的ws值 int ws = node.waitStatus; // 将当前节点的ws值置0 if (w 阅读全文
posted @ 2020-09-01 15:44 小窝蜗 阅读(238) 评论(0) 推荐(0)
摘要: 1.acquireQueued(Node, int) 源码: final boolean acquireQueued(final Node node, int arg) { // 标识是否获取资源失败 boolean failed = true; try { // 标识当前线程是否被中断过 bool 阅读全文
posted @ 2020-09-01 15:35 小窝蜗 阅读(1704) 评论(2) 推荐(1)
上一页 1 ··· 7 8 9 10 11 12 13 14 15 ··· 23 下一页