java计数器类counter_关于ehcache基于java.util.concurrent.atomic.AtomicLong实现的Counter计数器源码说明...

本文深入解析Ehcache库中基于`AtomicLong`实现的`Counter`接口及其`CounterImpl`实现类,详细介绍了相关方法的功能及其实现逻辑,包括增量、减量、设置和获取值等操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、前言

关于ehcache源码包中net.sf.ehcache.util.counter.Counter、net.sf.ehcache.util.counterCounterImpl线程计数器定义实现类,具体参考如下说明。

二、源码说明

1.Counter计数器接口package net.sf.ehcache.util.counter;@b@@b@public abstract interface Counter@b@{@b@  public abstract long increment();@b@@b@  public abstract long decrement();@b@@b@  public abstract long getAndSet(long paramLong);@b@@b@  public abstract long getValue();@b@@b@  public abstract long increment(long paramLong);@b@@b@  public abstract long decrement(long paramLong);@b@@b@  public abstract void setValue(long paramLong);@b@}

2.CounterImpl计数器实现类package net.sf.ehcache.util.counter;@b@@b@import java.io.Serializable;@b@import java.util.concurrent.atomic.AtomicLong;@b@@b@public class CounterImpl@b@  implements Counter, Serializable@b@{@b@  private AtomicLong value;@b@@b@  public CounterImpl()@b@  {@b@    this(0L);@b@  }@b@@b@  public CounterImpl(long initialValue)@b@  {@b@    this.value = new AtomicLong(initialValue);@b@  }@b@@b@  public long increment()@b@  {@b@    return this.value.incrementAndGet();@b@  }@b@@b@  public long decrement()@b@  {@b@    return this.value.decrementAndGet();@b@  }@b@@b@  public long getAndSet(long newValue)@b@  {@b@    return this.value.getAndSet(newValue);@b@  }@b@@b@  public long getValue()@b@  {@b@    return this.value.get();@b@  }@b@@b@  public long increment(long amount)@b@  {@b@    return this.value.addAndGet(amount);@b@  }@b@@b@  public long decrement(long amount)@b@  {@b@    return this.value.addAndGet(amount * -1L);@b@  }@b@@b@  public void setValue(long newValue)@b@  {@b@    this.value.set(newValue);@b@  }@b@}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值