public class LongAccumulator extends Number implements Serializable
long
值更新,使用提供的功能。当更新(方法
accumulate(long)
)主张跨线程、变量的设置可以动态增长以减少争用。方法
get()
(或者,等价地,
longValue()
)返回当前值在变量保持更新。
这类通常是最好的AtomicLong
当多个线程更新一个共同的价值,是用来为目的,如收集统计,不为细粒度的同步控制。在低更新争用下,两个类具有相似的特征。但在高争用,预计这一类的吞吐量显着更高,在更高的空间消耗的费用。
在或跨线程的积累的顺序是没有保证,不能依靠,所以这个类只适用于函数的积累,没有关系。所提供的蓄电池功能应该是免费的,因为它可能被重新应用时尝试更新失败,由于线程之间的争用。函数以当前值作为其第一个参数,并且给出的更新作为第二个参数。例如,保持最大值,你可以供应Long::max
随着Long.MIN_VALUE
身份。
类LongAdder
提供维护计数和常见的特殊情况,这一类的功能类似物。电话new LongAdder()
相当于new LongAccumulator((x, y) -> x + y, 0L
。
这类Number
延伸,但不定义方法如equals
,hashCode
和compareTo
因为情况预计将发生突变,而不是用作收集钥匙。
Constructor and Description |
---|
LongAccumulator(LongBinaryOperator accumulatorFunction, long identity)
使用给定的“生成”函数和标识元素创建一个新实例。
|
Modifier and Type | Method and Description |
---|---|
void |
accumulate(long x)
具有给定值的更新。
|
double |
doubleValue()
为扩大基本转换后的
double 返回
current value。
|
float |
floatValue()
为扩大基本转换后的
float 返回
current value。
|
long |
get()
返回当前值。
|
long |
getThenReset()
|
int |
intValue()
作为一个窄化转换后,
int 返回
current value。
|
long |
longValue()
相当于
get() 。
|
void |
reset()
重置变量保持更新的价值认同。
|
String |
toString()
返回当前值的字符串表示形式。
|
byteValue, shortValue
public LongAccumulator(LongBinaryOperator accumulatorFunction, long identity)
accumulatorFunction
-两参数无副作用的功能
identity
身份(初始值)为蓄能器的功能
public void accumulate(long x)
x
-价值
public long get()
public void reset()
public long getThenReset()
public int intValue()
int
返回
current value。
public float floatValue()
float
返回
current value。
floatValue
方法重写,继承类
Number
float
后。
public double doubleValue()
double
返回
current value。
doubleValue
方法重写,继承类
Number
double
后。
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.