Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is @sun.misc.Contended annotation's value?

In java-8 the new annotation @sun.misc.Contended appears.

There are several well written articles, which explain what it does and how to use it:

  • What is @Contended and False Sharing ?
  • @Contended (a.k.a. JEP 142)
  • Java @Contended annotation to help reduce false sharing

But what is not explained anywhere, is what is the value of this annotation? I mean, for example in java.lang.Thread it is used like:

@sun.misc.Contended("tlr")
int threadLocalRandomProbe;

What is this "tlr" value? What does it influence? What will happen if this value will be default (empty)?

like image 793
Andremoniy Avatar asked Dec 30 '15 11:12

Andremoniy


1 Answers

Taken from grepcode.com -> Contended:

A @Contended field annotation may optionally include a contention group tag. A contention group defines a set of one or more fields that collectively must be isolated from all other contention groups. The fields in the same contention group may not be pairwise isolated. With no contention group tag (or with the default empty tag: "") each @Contended field resides in its own distinct and anonymous contention group.

The value is documented with

The (optional) contention group tag. This tag is only meaningful for field level annotations.

Therefore the "tlr" is simply a chose group name for this int threadLocalRandomProbe - if you annotate a second variable with the same group tag they will be grouped together and isolated together.

like image 85
luk2302 Avatar answered Oct 11 '22 14:10

luk2302