哆啦a梦为什么没有耳朵| 扬州瘦马什么意思| 虎是什么结构| tmt是什么意思| 脚指甲发白是什么原因| 乳腺增生吃什么药好| 瞬息万变什么意思| 疳积是什么意思| 梦见着火了是什么意思| imp是什么意思| 舌头开裂吃什么药| 一到晚上就饿什么原因| 无力感是什么意思| 硝酸是什么| 头皮屑大块是什么原因| CA是什么激素| 政协委员是什么级别| 阿弥陀佛什么意思| 血小板计数是什么意思| 抑郁看病看什么科| 豉油是什么油| 什么的浪花| 小孩子经常流鼻血是什么原因| 子宫内膜什么时候脱落| 洧是什么意思| 定夺是什么意思| 什么是碱性食物| 肩膀上的肌肉叫什么| 夫妻肺片有什么材料| 花椒泡脚有什么好处| 礼是什么意思| 抵牾是什么意思| 一个鸟一个衣是什么字| 扁桃体结石是什么原因引起的| 什么闻乐见| 醋泡什么壮阳最快| 腿肿应该挂什么科| 甘胆酸是查什么的| 女人梦见好多蛇是什么预兆| chb是什么意思| 公分是什么| 做ct挂什么科| 老本行是什么意思| 6.26是什么星座| 身体铅超标有什么危害| 阴性是什么意思| 复机是什么意思| 吃石斛有什么好处| 小便尿道刺痛吃什么药| 宝宝吃什么增强抵抗力| c1和c2有什么区别| 中位生存期什么意思| 四氯化碳是什么| 沧海是什么意思| 柔软对什么| 欧了是什么意思| 高温天气喝什么茶解暑| 米酒发酸是什么原因| 1893年属什么| 用盐泡脚有什么好处| 小猫的特点是什么| 老虎菜是什么菜| 吃什么能生精和提高精子质量| 什么不及| 肾动脉狭窄有什么症状| 羊水偏少对胎儿有什么影响| 长河落日圆什么意思| 胃发炎吃什么药好得快| 新加坡什么工作最挣钱| 失聪是什么意思| 洋桔梗花语是什么| 张嘴睡觉是什么原因| 尿道口流脓吃什么药| 桥本氏甲状腺炎吃什么药| 孩子吐了吃什么药| 吃软不吃硬是什么生肖| 什么叫周围神经病| 尿素氮是什么| 黄瓜和什么一起炒好吃| 例假可以吃什么水果| 母亲o型父亲b型孩子是什么血型| 好汉不吃眼前亏是什么意思| 山竹是什么味道| 周杰伦英文名叫什么| 胰腺炎是什么症状| 肠粘连是什么原因引起| 感冒吃什么水果好得快| 牟作为姓氏时读什么| 肚子胀气放屁吃什么药| 早餐做什么| 红萝卜和胡萝卜有什么区别| 乜贴是什么意思| 心脏在人体什么位置| 陶渊明是什么朝代| 玫瑰痤疮吃什么药| 鸟飞进家里是什么预兆| 肌酐高吃什么水果好| 戌时右眼跳是什么预兆| 1975年属兔是什么命| 浅蓝色裙子配什么颜色上衣好看| 今天吃什么| 术后改变是什么意思| 成双成对是什么生肖| 生不如死是什么生肖| 斗米恩升米仇什么意思| 天秤座跟什么星座最配| 葵瓜子吃多了有什么危害| 火彩是什么| 人为什么会困| 尿频是什么原因| 梦笔生花的意思是什么| 晨起嘴苦是什么原因| 败血症是什么| 头顶发热是什么原因| 绞股蓝长什么样子| 为什么睡觉会打呼| 蹲久了站起来头晕是什么原因| 蜻蜓是什么目| 白矾是什么东西| 头痛到医院挂什么科| 因为什么| 什么像什么似的什么造句| 阴唇肥大是什么原因| 梦见怀孕是什么意思| 安字属于五行属什么| 为什么会阑尾炎| 狗屎运是什么意思| 尿酸高能喝什么酒| 什么年龄割双眼皮最好| 孕妇缺铁吃什么食物好| 关节退行性改变是什么意思| 马失前蹄下一句是什么| 血性是什么意思| cindy英文名什么意思| 什么情况下不能献血| 风致是什么意思| 胸透是查什么的| 低钾会出现什么症状| 木菠萝什么时候成熟| 三生三世是什么意思| 一流是什么意思| 农历5月20日是什么星座| 偏光太阳镜是什么意思| 什么人容易得心理疾病| 杳什么意思| xpe是什么材料| 现代是什么时候| 蝙蝠飞到家里是什么预兆| 小孩脚后跟疼是什么原因| 生理期不能吃什么水果| 傧相是什么意思| 淋巴结炎吃什么药| 肚脐眼左右两边疼是什么原因| 85年属什么的| 伸什么缩什么| 女人大姨妈来了吃什么最好| 左手虎口有痣代表什么| 五二年属什么生肖| 为什么会得带状疱疹| 血常规用什么颜色的试管| 陪产假什么时候开始休| 什么朦胧| 姝姝是什么意思| 小腿发麻是什么原因| rm什么意思| 晚上睡不着什么原因| 墨蓝色是什么颜色| 相亲第一次见面送什么礼物好| 穿什么衣服| 猪胰子是什么东西| 为什么会脱发| 精美的什么| 空调的睡眠模式是什么意思| 增大摩擦力的方法有什么| 什么是失眠| 疖肿是什么原因引起的| 四十年婚姻是什么婚| 蜂蜜加柠檬有什么功效和作用| 腰痛宁胶囊为什么要用黄酒送服| 石斛花有什么功效| 白是什么意思| 粉红粉红的什么| 间质性改变是什么意思| 做试管前需要检查什么项目| 牵引车是什么车| 黑洞是什么东西| 张予曦为什么像混血| 高危病变是什么意思| 2月20日是什么星座| gaba是什么| 善存片适合什么人吃| 偏头痛是什么原因引起的| dmdm乙内酰脲是什么| 胸口出汗是什么原因| 大海里面有什么| 中耳炎吃什么消炎药| 什么茶叶能减肥刮油脂肪| 腿有淤青是什么原因| 舌苔发紫是什么原因| 什么的哲理| 中午一点半是什么时辰| babycare是什么牌子| 胆囊炎可以吃什么水果| 老年人适合喝什么牛奶| 来月经腰疼是什么原因| 开团什么意思| 扎马步有什么好处| 打呼噜有什么危害| 兆上面是什么单位| 考试前紧张吃什么药最好能缓解| 7月1号是什么节日| 可心是什么意思| 什么情况下要做宫腔镜| 阴道炎用什么药最好| 五月二十四号是什么星座| 女性肛门瘙痒用什么药| 三点水加个及念什么| 防字代表什么生肖| 蚂蚁为什么要搬家| 山楂和什么不能一起吃| 鸡眼长什么样子图片| 黄连泡水喝能治什么病| 弄虚作假是什么生肖| 小孩尿味道很重是什么原因| 怀孕吃什么水果比较好| 上半身胖属于什么体质| 11.1是什么星座| 十二生肖本领强是什么生肖| 三月二十六是什么星座| 推崇是什么意思| 血尿是什么原因引起的| 唇炎属于什么科| loho是什么牌子| 你喜欢我什么| 拙作是什么意思| 左派是什么意思| 叒怎么读音是什么意思| 什么行业赚钱| 克加寸念什么| 吻合是什么意思| 米糠是什么| 今年为什么闰六月| 808什么意思| 心肌桥是什么病| 老鹰代表什么生肖| 什么然起什么| 尼古丁是什么东西| 野兽之王是什么动物| 安全期是什么意思| 88年五行属什么| 西湖醋鱼是什么菜系| dp是什么意思| 意中人是什么意思| 什么是唐氏儿| 脑血管堵塞有什么症状| amber是什么意思| 为什么都开头孢不开阿莫西林| 膝盖痛吃什么药| 香蕉不能和什么一起吃| esr是什么意思| 事宜愿为是什么意思| 新生儿什么时候可以喝水| 塔罗牌是什么| 哀大莫过于心死是什么意思| 百度
Partner – Microsoft – NPI EA (cat = Baeldung)
announcement - icon

Azure Container Apps is a fully managed serverless container service that enables you to build and deploy modern, cloud-native Java applications and microservices at scale. It offers a simplified developer experience while providing the flexibility and portability of containers.

Of course, Azure Container Apps has really solid support for our ecosystem, from a number of build options, managed Java components, native metrics, dynamic logger, and quite a bit more.

To learn more about Java features on Azure Container Apps, visit the documentation page.

You can also ask questions and leave feedback on the Azure Container Apps GitHub page.

Partner – Microsoft – NPI EA (cat= Spring Boot)
announcement - icon

Azure Container Apps is a fully managed serverless container service that enables you to build and deploy modern, cloud-native Java applications and microservices at scale. It offers a simplified developer experience while providing the flexibility and portability of containers.

Of course, Azure Container Apps has really solid support for our ecosystem, from a number of build options, managed Java components, native metrics, dynamic logger, and quite a bit more.

To learn more about Java features on Azure Container Apps, you can get started over on the documentation page.

And, you can also ask questions and leave feedback on the Azure Container Apps GitHub page.

Partner – Orkes – NPI EA (cat=Spring)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

Partner – Orkes – NPI EA (tag=Microservices)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

eBook – Guide Spring Cloud – NPI EA (cat=Spring Cloud)
announcement - icon

Let's get started with a Microservice Architecture with Spring Cloud:

>> Join Pro and download the eBook

eBook – Mockito – NPI EA (tag = Mockito)
announcement - icon

Mocking is an essential part of unit testing, and the Mockito library makes it easy to write clean and intuitive unit tests for your Java code.

Get started with mocking and improve your application tests using our Mockito guide:

Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Reactive – NPI EA (cat=Reactive)
announcement - icon

Spring 5 added support for reactive programming with the Spring WebFlux module, which has been improved upon ever since. Get started with the Reactor project basics and reactive programming in Spring Boot:

>> Join Pro and download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Jackson – NPI EA (cat=Jackson)
announcement - icon

Do JSON right with Jackson

Download the E-book

eBook – HTTP Client – NPI EA (cat=Http Client-Side)
announcement - icon

Get the most out of the Apache HTTP Client

Download the E-book

eBook – Maven – NPI EA (cat = Maven)
announcement - icon

Get Started with Apache Maven:

Download the E-book

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

eBook – RwS – NPI EA (cat=Spring MVC)
announcement - icon

Building a REST API with Spring?

Download the E-book

Course – LS – NPI EA (cat=Jackson)
announcement - icon

Get started with Spring and Spring Boot, through the Learn Spring course:

>> LEARN SPRING
Course – RWSB – NPI EA (cat=REST)
announcement - icon

Explore Spring Boot 3 and Spring 6 in-depth through building a full REST API with the framework:

>> The New “REST With Spring Boot”

Course – LSS – NPI EA (cat=Spring Security)
announcement - icon

Yes, Spring Security can be complex, from the more advanced functionality within the Core to the deep OAuth support in the framework.

I built the security material as two full courses - Core and OAuth, to get practical with these more complex scenarios. We explore when and how to use each feature and code through it on the backing project.

You can explore the course here:

>> Learn Spring Security

Course – LSD – NPI EA (tag=Spring Data JPA)
announcement - icon

Spring Data JPA is a great way to handle the complexity of JPA with the powerful simplicity of Spring Boot.

Get started with Spring Data JPA through the guided reference course:

>> CHECK OUT THE COURSE

Partner – MongoDB – NPI EA (tag=MongoDB)
announcement - icon

Traditional keyword-based search methods rely on exact word matches, often leading to irrelevant results depending on the user's phrasing.

By comparison, using a vector store allows us to represent the data as vector embeddings, based on meaningful relationships. We can then compare the meaning of the user’s query to the stored content, and retrieve more relevant, context-aware results.

Explore how to build an intelligent chatbot using MongoDB Atlas, Langchain4j and Spring Boot:

>> Building an AI Chatbot in Java With Langchain4j and MongoDB Atlas

eBook – Java Concurrency – NPI (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

1. Overview

In this article, we’ll see how sometimes false sharing can turn multithreading against us.

First, we’re going to start with a little bit on the theory of caching and spatial locality. Then we’ll rewrite the?LongAdder?concurrent utility and benchmark it against the?java.util.concurrent?implementation. Throughout the article, we’ll use the benchmark results at different levels to investigate the effect of false sharing.

The Java-related part of the article depends heavily on the memory layout of objects. Since these layout details are not part of the JVM specification and are left to the discretion of the implementor, we’ll only focus on one specific JVM implementation: the HotSpot JVM. We may also use the JVM and HotSpot JVM terms interchangeably throughout the article.

2. Cache Line and Coherency

Processors use different levels of caching — when a processor reads a value from the main memory, it may cache that value to improve performance.

As it turns out, most modern processors not only cache the requested value but also cache a few more nearby values. This optimization is based on the idea of spatial locality and can significantly improve the overall performance of applications.?Simply put, processor caches are working in terms of cache lines, instead of single cacheable values.

When multiple processors are operating on the same or nearby memory locations, they may end up sharing the same cache line. In such situations, it’s essential to keep those overlapping caches in different cores consistent with each other. The act of maintaining such consistency is called cache coherency.

There are quite a few protocols to maintain the cache coherency between CPU cores. In this article, we’re going to talk about the MESI protocol.

2.1. The MESI Protocol

In the MESI protocol, each cache line can be in one of these four distinct states: Modified, Exclusive, Shared, or Invalid. The word MESI is the acronym of these states.

To better understand how this protocol works, let’s walk through an example. Suppose two cores are going to read from nearby memory locations:

false-sharing-exclusive

Core?A?reads the value of a?from the main memory. As shown above, this core fetches a few more values from the memory and stores them into a cache line. Then it marks that cache line as exclusive?since core?A?is the only core operating on this cache line. From now on, when possible, this core will avoid the inefficient memory access by reading from the cache line instead.

After a while, core?B also decides to read the value of b?from the main memory:

false-sharing-shared

Since?a?and?b?are so close to each other and reside in the same cache line, both cores will tag their cache lines as shared.

Now, let’s suppose that core A?decides to change the value of?a:false-sharing-invalid

The core A stores this change only in its store buffer and marks its cache line as modified. Also, it communicates this change to the core?B,?and this core will, in turn, mark its cache line as invalid.

That’s how different processors make sure that their caches are coherent with each other.

3. False Sharing

Now, let’s see what happens when core B?decides to re-read the value of b. As this value didn’t change recently, we might expect a fast read from the cache line. However, the nature of shared multiprocessor architecture invalidates this expectation in reality.

As mentioned earlier, the whole cache line was shared between the two cores. Since the cache line for core?B?is invalid now, it should read the value b?from the main memory again:

false-sharing-flush

As shown above, reading the same?b?value from the main memory is not the only inefficiency here. This memory access will force the core?A?to flush its store buffer, as the core?B?needs to get the latest value. After flushing and fetching the values, both cores will end up with the latest cache line version tagged in the shared state again:

false-sharing-shared-again

So, this imposes a cache miss to one core and an early buffer flush to another one, even though the two cores weren’t operating on the same memory location. This phenomenon, known as false sharing, can hurt the overall performance, especially when the rate of the cache misses is high. To be more specific, when this rate is high, processors will constantly reach out to the main memory instead of reading from their caches.

4. Example: Dynamic Striping

To demonstrate how false sharing can affect the throughput or latency of applications, we’re going to cheat in this section. Let’s define two empty classes:

abstract class Striped64 extends Number {}
public class LongAdder extends Striped64 implements Serializable {}

Of course, empty classes aren’t that useful, so let’s copy-paste some logic into them.

For our?Striped64?class, we can copy everything from the?java.util.concurrent.atomic.Striped64?class and paste it into our class. Please make sure to copy the?import?statements, too. Also, if using Java 8, we should make sure to replace any call to?sun.misc.Unsafe.getUnsafe()?method to a custom one:

private static Unsafe getUnsafe() {
    try {
        Field field = Unsafe.class.getDeclaredField("theUnsafe");
        field.setAccessible(true);

        return (Unsafe) field.get(null);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

We can’t call the?sun.misc.Unsafe.getUnsafe()?from our application classloader, so we have to cheat again with this static method.?As of Java 9, however, the same logic is implemented using?VarHandles, so we won’t need to do anything special there, and just a simple copy-paste would suffice.

For the?LongAdder?class, let’s copy everything from the?java.util.concurrent.atomic.LongAdder?class and paste it into ours. Again, we should copy the import?statements, too.

Now, let’s benchmark these two classes against each other: our custom?LongAdder?and java.util.concurrent.atomic.LongAdder.

4.1. Benchmark

To benchmark these classes against each other, let’s write a simple JMH benchmark:

@State(Scope.Benchmark)
public class FalseSharing {

    private java.util.concurrent.atomic.LongAdder builtin = new java.util.concurrent.atomic.LongAdder();
    private LongAdder custom = new LongAdder();

    @Benchmark
    public void builtin() {
        builtin.increment();
    }

    @Benchmark
    public void custom() {
        custom.increment();
    }
}

If we run this benchmark with two forks and 16 threads in throughput benchmark mode (the equivalent of passing -bm thrpt -f 2 -t 16″?arguments), then JMH will print these stats:

Benchmark              Mode  Cnt          Score          Error  Units
FalseSharing.builtin  thrpt   40  523964013.730 ± 10617539.010  ops/s
FalseSharing.custom   thrpt   40  112940117.197 ±  9921707.098  ops/s

The result doesn’t make sense at all. The JDK built-in implementation dwarfs our copy-pasted solution by almost 360% more throughput.

Let’s see the difference between latencies:

Benchmark             Mode  Cnt   Score   Error  Units
FalseSharing.builtin  avgt   40  28.396 ± 0.357  ns/op
FalseSharing.custom   avgt   40  51.595 ± 0.663  ns/op

As shown above, the built-in solution also has better latency characteristics.

To better understand what’s so different about these seemingly identical implementations, let’s inspect some low-level performance monitoring counters.

5. Perf Events

To instrument low-level CPU events, such as cycles, stall cycles, instructions per cycle, cache loads/misses, or memory loads/stores, we can program special hardware registers on the processors.

As it turns out, tools like perf or eBPF are already using this approach to expose useful metrics. As of Linux 2.6.31, perf is the standard Linux profiler capable of exposing useful Performance Monitoring Counters or PMCs.

So, we can use?perf events to see what’s going on at the CPU level when running each of these two benchmarks. For instance, if we run:

perf stat -d java -jar benchmarks.jar -f 2 -t 16 --bm thrpt custom

Perf will make JMH run the benchmarks against the copy-pasted solution and print the stats:

161657.133662      task-clock (msec)         #    3.951 CPUs utilized
         9321      context-switches          #    0.058 K/sec
          185      cpu-migrations            #    0.001 K/sec
        20514      page-faults               #    0.127 K/sec
            0      cycles                    #    0.000 GHz
 219476182640      instructions
  44787498110      branches                  #  277.052 M/sec
     37831175      branch-misses             #    0.08% of all branches
  91534635176      L1-dcache-loads           #  566.227 M/sec
   1036004767      L1-dcache-load-misses     #    1.13% of all L1-dcache hits

The?L1-dcache-load-misses?field represents the number of cache misses for the L1 data cache. As shown above, this solution has encountered around one billion cache misses (1,036,004,767 to be exact). If we gather the same stats for the built-in approach:

161742.243922      task-clock (msec)         #    3.955 CPUs utilized
         9041      context-switches          #    0.056 K/sec
          220      cpu-migrations            #    0.001 K/sec
        21678      page-faults               #    0.134 K/sec
            0      cycles                    #    0.000 GHz
 692586696913      instructions
 138097405127      branches                  #  853.812 M/sec
     39010267      branch-misses             #    0.03% of all branches
 291832840178      L1-dcache-loads           # 1804.308 M/sec
    120239626      L1-dcache-load-misses     #    0.04% of all L1-dcache hits

We would see that it encounters a lot fewer cache misses (120,239,626 ~ 120 million) compared to the custom approach. Therefore, the high number of cache misses might be the culprit for such a difference in performance.

Let’s dig even deeper into the internal representation of?LongAdder?to find the actual culprit.

6. Dynamic Striping Revisited

The?java.util.concurrent.atomic.LongAdder?is an atomic counter implementation with high throughput. Instead of just using one counter, it’s using an array of them to distribute the memory contention between them. This way, it will outperform the simple atomics such as?AtomicLong?in highly contended applications.

The Striped64?class is responsible for this distribution of memory contention, and?this is how this?class implements those?array of counters:

@jdk.internal.vm.annotation.Contended 
static final class Cell {
    volatile long value;
    // omitted
}
transient volatile Cell[] cells;

Each Cell?encapsulates the details for each counter. This implementation makes it possible for different threads to update different memory locations. Since we’re using an array (that is, stripes) of states, this idea is called dynamic striping. Interestingly, Striped64?is named after this idea and the fact that it works on 64-bit data types.

Anyway, the JVM may allocate those counters near each other in the heap. That is, a few those counters will be in the same cache line. Therefore, updating one counter may invalidate the cache for nearby counters.

The key takeaway here is, the naive implementation of dynamic striping will suffer from false sharing. However, by adding enough padding around each counter, we can make sure that each of them resides on its cache line, thus preventing the false sharing:

false-sharing-padding

As it turns out, the?@jdk.internal.vm.annotation.Contended?annotation is responsible for adding this padding.

The only question is, why didn’t?this annotation work in the copy-pasted implementation?

7. Meet?@Contended

Java 8 introduced the?sun.misc.Contended?annotation (Java 9 repackaged it under the jdk.internal.vm.annotation?package) to prevent false sharing.

Basically, when we annotate a field with this annotation, the HotSpot JVM will add some paddings around the annotated field. This way, it can make sure that the field resides on its own cache line. Moreover, if we annotate a whole class with this annotation, the HotSopt JVM will add the same padding before all the fields.

The?@Contended?annotation is meant to be used internally by the JDK itself. So by default, it doesn’t affect the memory layout of non-internal objects. That’s the reason why our copy-pasted adder doesn’t perform as well as the built-in one.

To remove this internal-only restriction, we can use the -XX:-RestrictContended?tuning flag when rerunning the benchmark:

Benchmark              Mode  Cnt          Score          Error  Units
FalseSharing.builtin  thrpt   40  541148225.959 ± 18336783.899  ops/s
FalseSharing.custom   thrpt   40  546022431.969 ± 16406252.364  ops/s

As shown above, now the benchmark results are much closer, and the difference probably?is just a bit of noise.

7.1. Padding Size

By default, the?@Contended?annotation adds 128 bytes of padding. That’s mainly because the cache line size in many modern processors is around 64/128 bytes.

This value, however, is configurable through the?-XX:ContendedPaddingWidth?tuning flag. As of this writing, this flag only accepts values between 0 and 8192.

7.2. Disabling the?@Contended

It’s also possible to disable the?@Contended?effect via the?-XX:-EnableContended?tuning. This may prove to be useful when the memory is at a premium and we can afford to lose a bit (and sometimes a lot) of performance.

7.3. Use Cases

After its first release, the?@Contended?annotation has been used quite extensively to prevent false sharing in JDK’s internal?data structures. Here are a few notable examples of such implementations:

8. Conclusion

In this article, we saw how sometimes false sharing might cause counterproductive effects on the performance of multithreaded applications.

To make matters more concrete, we did benchmark the?LongAdder?implementation in Java against its copy and used its results as a starting point for our performance investigations.

Also, we used the?perf?tool to gather some stats about the performance metrics of a running application on Linux. To see more examples of?perf,?it’s highly recommended to read Branden Greg‘s blog. Moreover, eBPF, available as of Linux Kernel version 4.4, can also be useful in many tracing and profiling scenarios.

The code backing this article is available on GitHub. Once you're logged in as a Baeldung Pro Member, start learning and coding on the project.
Baeldung Pro – NPI EA (cat = Baeldung)
announcement - icon

Baeldung Pro comes with both absolutely No-Ads as well as finally with Dark Mode, for a clean learning experience:

>> Explore a clean Baeldung

Once the early-adopter seats are all used, the price will go up and stay at $33/year.

Partner – Microsoft – NPI EA (cat = Baeldung)
announcement - icon

Azure Container Apps is a fully managed serverless container service that enables you to build and deploy modern, cloud-native Java applications and microservices at scale. It offers a simplified developer experience while providing the flexibility and portability of containers.

Of course, Azure Container Apps has really solid support for our ecosystem, from a number of build options, managed Java components, native metrics, dynamic logger, and quite a bit more.

To learn more about Java features on Azure Container Apps, visit the documentation page.

You can also ask questions and leave feedback on the Azure Container Apps GitHub page.

Partner – Microsoft – NPI EA (cat = Spring Boot)
announcement - icon

Azure Container Apps is a fully managed serverless container service that enables you to build and deploy modern, cloud-native Java applications and microservices at scale. It offers a simplified developer experience while providing the flexibility and portability of containers.

Of course, Azure Container Apps has really solid support for our ecosystem, from a number of build options, managed Java components, native metrics, dynamic logger, and quite a bit more.

To learn more about Java features on Azure Container Apps, visit the documentation page.

You can also ask questions and leave feedback on the Azure Container Apps GitHub page.

Partner – Orkes – NPI EA (cat = Spring)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

Partner – Orkes – NPI EA (tag = Microservices)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

eBook – HTTP Client – NPI EA (cat=HTTP Client-Side)
announcement - icon

The Apache HTTP Client is a very robust library, suitable for both simple and advanced use cases when testing HTTP endpoints. Check out our guide covering basic request and response handling, as well as security, cookies, timeouts, and more:

>> Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

Partner – MongoDB – NPI EA (tag=MongoDB)
announcement - icon

Traditional keyword-based search methods rely on exact word matches, often leading to irrelevant results depending on the user's phrasing.

By comparison, using a vector store allows us to represent the data as vector embeddings, based on meaningful relationships. We can then compare the meaning of the user’s query to the stored content, and retrieve more relevant, context-aware results.

Explore how to build an intelligent chatbot using MongoDB Atlas, Langchain4j and Spring Boot:

>> Building an AI Chatbot in Java With Langchain4j and MongoDB Atlas

Course – LS – NPI EA (cat=REST)

announcement - icon

Get started with Spring Boot and with core Spring, through the Learn Spring course:

>> CHECK OUT THE COURSE

eBook – Java Concurrency – NPI (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook Jackson – NPI EA – 3 (cat = Jackson)
王源粉丝叫什么 云南白药里面的保险子有什么用 怎么知道自己五行缺什么 白果治什么病 泌尿科主要看什么病
胃胀肚子胀吃什么药 穿匡威的都是什么人 什么是公职人员 1129是什么星座 什么字属金
为什么可乐能溶解鱼刺 脾气是什么意思 1986年属什么生肖 男性性功能障碍吃什么药 口腔溃疡挂什么科就诊
阴霾是什么意思 啵是什么意思 麦冬有什么作用与功效 大红袍属于什么茶类 妈妈的舅舅叫什么
四大美女指什么生肖hcv8jop9ns8r.cn 胡萝卜是什么科hcv9jop4ns6r.cn 麻鸡是什么鸡hcv7jop5ns2r.cn 梦见生了个孩子是什么意思hcv9jop6ns0r.cn 脑梗吃什么药好hcv7jop9ns1r.cn
心猿意马是什么意思hcv9jop0ns1r.cn 什么除湿气效果最好hcv9jop4ns5r.cn 双侧乳腺小叶增生是什么意思clwhiglsz.com 查性激素六项挂什么科gangsutong.com 胃痛胃胀什么原因引起的hcv7jop6ns7r.cn
眼睛为什么不怕冷hcv8jop7ns6r.cn 咳嗽不能吃什么hcv8jop2ns2r.cn 心率低吃什么药最好creativexi.com 舌有裂纹是什么原因hcv8jop6ns9r.cn 黉门是什么意思hcv9jop8ns0r.cn
木丑念什么hcv7jop9ns0r.cn 技师是干什么的hcv8jop9ns3r.cn 水牛背满月脸是什么病hcv8jop7ns7r.cn 罗勒是什么hcv9jop5ns6r.cn bull是什么意思wuhaiwuya.com
百度