Which class does LongAdder extends?
As shown in the source, it extends Striped64
. Since that class is not public API, however, the Javadoc doesn't tell you that.
Javadoc, by default, only generates documentation for public
and protected
members; in other words, only the public API is documented 1 . The Striped64
class is package-private and is thus not documented. Since the class is not documented the next closest documented ancestor is found, which happens to be Number
in this case. Note you could have a documented class Foo
that has 15+ ancestors, but if none of those ancestors are public API the Javadoc will show Foo extends Object
.
From the perspective of public API versus private API, the fact LongAdder
extends Striped64
is irrelevant. The latter class is an implementation detail (ie private API). It's the public API that defines the contracts of a library; hence a user only cares that LongAdder
is a subclass of Number
in this case.
You can configure Javadoc to document everything, including package-private and private
members, if needed. However, the generated documentation should probably only be for private use (eg internal to the organization maintaining the library).
1. What makes an API public or private is not solely based on the visibility modifier. What package the class is in is also relevant. For instance, the JDK has many classes in packages with prefixes such as com.sun
, oracle
, jdk.internal
, and so on. The classes in those packages are private API and are thus not documented in the publicly available Javadoc.
The idea of "private packages" obtained more official status in Java 9 with the advent of modules. Now you can explicitly declare which packages are exported by a module and this is enforced by the runtime.
They may be extending Number
class in LongAdder
, who knows ?
From Oracle Docs :
It can be concluded that LongAdder
uses AtomicLong
by extending Striped64
.
Q : Why Striped64 is extended by LongAdder ?
A :
Striped64
holds a hash table of Cells (where each Cell is a variant ofAtomicLong
). When multiple threads are used to add values to aLongAdder
(which extendsStriped64
), then the threads add their values to different cells in that hash table. This leads to concurrent thread processing and increases the throughput.
May be Striped64 is an internal implementation rather and they wanted it to be abstracted.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.