Skip to main content
Filter by
Sorted by
Tagged with
0 votes
3 answers
230 views

I often see both terms — JMM (Java Memory Model) and JVM (Java Virtual Machine) — when learning about multithreading and memory management in Java. However, I'm confused about how they relate to each ...
Nurlis Kimbiletov's user avatar
0 votes
1 answer
76 views

If in my class I have a field of type ImmutableMap like: private ImmutableMap<String, State> states = ImmutableMap.of(); And there is 1 reader thread and 1 writer thread Reader reads by calling ...
blonded04's user avatar
  • 531
3 votes
1 answer
208 views

I’m working with CompletableFuture in Java and want to understand how field updates made inside a CompletableFuture task are visible to the main thread after calling join(). Specifically, if I pass an ...
Kaepxer's user avatar
  • 412
4 votes
1 answer
217 views

Introduction Consider this Java program: public class Loop { static volatile boolean flag; public static void main(String[] args) { new Thread(() -> flag = true).start(); ...
Haspamelodica's user avatar
1 vote
2 answers
117 views

There seems to be a similar question (Java Specification: reads see writes that occur later in the execution order), but it focuses on a different example. The Java Memory Model states in §17.4.8: ...
yaskovdev's user avatar
  • 1,354
3 votes
1 answer
145 views

Do I understand correctly that if I run run1() and run2() in parallel, the result r1 == 0 and r2 == 0 is impossible under any circumstances, even though a and b are not volatile? public class Example {...
yaskovdev's user avatar
  • 1,354
0 votes
0 answers
64 views

I'm trying to understand the Memory Model chapter from the Java Language Specification, but I'm already confused by the first two paragraphs: A memory model describes, given a program and an ...
yaskovdev's user avatar
  • 1,354
1 vote
1 answer
141 views

I am trying to understand how Java handles memory allocation for lambdas and whether it's possible to use them in a GC-free style for latency-critical applications. My goal is to determine if lambdas ...
Vlad's user avatar
  • 652
4 votes
2 answers
198 views

I was reading this: https://en.m.wikipedia.org/wiki/Double-checked_locking And in section Usage in Java, last example: Semantics of final field in Java 5 can be employed to safely publish the helper ...
lol's user avatar
  • 3,388
-1 votes
1 answer
92 views

I am reading an article about the Java Volatile keyword, got some questions. click here public class SharedObject { public int counter = 0; } Imagine too, that only Thread 1 increments the ...
qwee's user avatar
  • 29
1 vote
1 answer
89 views

Per the JMM, section 9.2.3 The rules for class initialization ensure that any thread that reads a static field will be synchronized with the static initialization of that class. I am trying to ...
alex01011's user avatar
  • 1,712
1 vote
1 answer
91 views

@JCStressTest @Outcome(id = "1, 1", expect = Expect.ACCEPTABLE, desc = "ordered") @Outcome(id = "0, 1", expect = Expect.ACCEPTABLE, desc = "ordered") @...
qwee's user avatar
  • 29
0 votes
4 answers
470 views

I have a question regarding the Java Memory Model (JMM), particularly in the context of x86 architecture, which I find quite intriguing. One of the most confusing and often debated topics is the ...
Dmytro Kostenko's user avatar
0 votes
2 answers
123 views

By Default Java stores strings in UTF-16, in my application it is using huge memory. One of the suggestion we get is to convert UTF-16 to UTF-8 so some memory can be saved. is this True ? If yes Can I ...
user2108383's user avatar
0 votes
2 answers
83 views

I'm trying to understand the Happens Before mechanism and i can't find any source in the internet talking about happens-before relationship between a READ and subsequent WRITE. I can only read about ...
Unearthly's user avatar
  • 169
2 votes
1 answer
79 views

I have a class like this: class MyClass { private val myLock = ReentrantLock() ... } In java I would make this field final to provide memory guarantees: https://stackoverflow.com/a/27254652/...
gstackoverflow's user avatar
2 votes
1 answer
187 views

Let's imagine we have some class with one volatile non-final field that we want to initialise with a default value passed through a constructor: public class MyClass { private volatile String s; ...
WildWind03's user avatar
1 vote
0 answers
79 views

If a member variable is updated by one thread and later read (not updated) by other treads from a thread pool, does that member variable needs to be declared as volatile? Made-up code to illustrate ...
SebastianBrandt's user avatar
2 votes
1 answer
86 views

Related to : In ConcurrentHashMap's transfer method, I don't understand the meaning of these two conditions "i >= n" and "i + n >= nextn" I am looking into the ...
ng.newbie's user avatar
  • 3,332
4 votes
2 answers
171 views

Lets have the following class: public class MyClass { private final List<String> myList = new ArrayList<>(); //Not a thread-safe thing // Called on thread 1 MyClass() { myList....
user996142's user avatar
  • 2,923
1 vote
3 answers
177 views

Consider two threads: A==B==0 (initially) Thread 1 Thread 2 B=42; if (A==1) A=1; ...print(B) To my knowledge if (at least) A is volatile we will only be able to read B==42 at the print. Though if only ...
l30c0d35's user avatar
  • 807
0 votes
1 answer
66 views

Question: Is this statement true: „A write to a volatile field happens-before every subsequent read of that or another volatile field.“ On How to understand happens-before consistent I found the ...
dibo's user avatar
  • 1
1 vote
0 answers
117 views

I don't understand how the JMM qualifies the usage of local variables inside lambdas (and also in local and anonymous classes). It looks like they aren't "shared variables" in terms of the ...
user avatar
0 votes
1 answer
332 views

I need your help. There is a reactive chain in a Spring WebFlux application that uses R2dbcRepository: entityRepository //0 .findById(entityId) //1 Mono<Entity> .doOnNext(e-> e....
user18032014's user avatar
-1 votes
2 answers
59 views

I am trying to understand the JMM by following the blog post by Aleksey Shipilëv The above example is breaking my mind. Explanation: There are 3 threads the first 2 threads (the 1st and 2nd column) ...
ng.newbie's user avatar
  • 3,332
2 votes
1 answer
172 views

"A write to a volatile field (§8.3.1.4) happens-before every subsequent read of that field." So I know that volatile field can be used as synchronization in order to guarantee that that all ...
Layosh M's user avatar
2 votes
1 answer
86 views

New memory ordering where added in JDK9, so I'm digging into Release/Acquire mode. It introduce causality constraint: If access A precedes interthread Release mode (or stronger) write W in source ...
lantalex's user avatar
0 votes
2 answers
161 views

Sample code: public class TestTestTest { private void setFalseFlag() { this.keepRunning = false; System.out.println("keepRunning is false"); } private boolean ...
Layosh M's user avatar
1 vote
0 answers
38 views

Can someone explain to me the meaning of 17.4.9. Observable Behavior and Nonterminating Executions. What I understand (kind of): this section exists because of the programs which never terminate: ...
tool's user avatar
  • 11
1 vote
2 answers
145 views

There is a term correctly synchronized in the JLS: A program is correctly synchronized if and only if all sequentially consistent executions are free of data races. If a program is correctly ...
JJJ's user avatar
  • 13
2 votes
1 answer
200 views

According to the Java Memory Model (JMM): A program is correctly synchronized if and only if all sequentially consistent executions are free of data races. If a program is correctly synchronized, ...
Har's user avatar
  • 23
2 votes
2 answers
165 views

JLS states this: A set of synchronization edges, S, is sufficient if it is the minimal set such that the transitive closure of S with the program order determines all of the happens-before edges in ...
cata's user avatar
  • 21
2 votes
3 answers
1k views

Consider the following code: public class MyDataStructure { int size; final ReentrantLock lock = new ReentrantLock(); public void update() { lock.lock(); try { ...
greenButMellow's user avatar
3 votes
1 answer
111 views

I recently stumbled upon this example in jcstress: @JCStressTest @State @Outcome(id = "10", expect = ACCEPTABLE, desc = "Boring") @Outcome(id = {&...
Dmytro Marchuk's user avatar
4 votes
2 answers
378 views

Consider the following simple Java application: public class Main { public int a; public volatile int b; public void thread1(){ int b; a = 1; b = this.b; } ...
Some Name's user avatar
  • 9,750
1 vote
1 answer
156 views

When dealing with happens before, I see it as about dealing with memory ordering and whether some memory ordering is valid with program order. For example, take the Dekker algorithm: public class ...
TwITe's user avatar
  • 450
2 votes
1 answer
61 views

I'm reading The Art of Multiprocessor Programming, 2nd ed. Sequential consistency is defined there this way: Sequential consistency requires that method calls act as if they occurred in a sequential ...
user19858110's user avatar
1 vote
4 answers
259 views

Does JMM guarantee the visibility of a synchronized write to the variable that is read in the other thread after a synchronized block? Here's what I mean: public class SynchronizedWriteRead { ...
TwITe's user avatar
  • 450
8 votes
1 answer
260 views

The memory model is defined in 17.4. Memory Model. The final field multi-threading guarantees are given in 17.5. final Field Semantics. I don't understand why these are separate sections. AFAIK both ...
poq's user avatar
  • 81
17 votes
3 answers
797 views

The following code sample shows a common way to demonstrate concurrency issues caused by a missing happens-before relationship. private static /*volatile*/ boolean running = true; public static ...
stonar96's user avatar
  • 1,501
5 votes
2 answers
407 views

The part of the language specification dedicated to the Java Memory Model (JMM) (link) mentions "execution trace" a lot. For example right from the start: A memory model describes, given a ...
sanyok's user avatar
  • 51
0 votes
1 answer
88 views

A very naive array based circular buffer implementation, import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; public class SomeRingBuffer { ...
Kapil's user avatar
  • 181
2 votes
1 answer
398 views

I have a very confused question about java volatile read. I will show two cases to explain my question. case1: class TestVolatile { public boolean running = true; public volatile boolean ...
Jack Liu's user avatar
2 votes
2 answers
559 views

The JVM spec says that each thread has its own working memory and lists several operations including use, assign, load, read, store, write, lock, unlock. Is working memory the same as the CPU cache, ...
Charles Ju's user avatar
  • 1,289
3 votes
1 answer
795 views

I'm running a jar using this command. Note the memory parameters. (The jar size is 56MB) java -jar -Xms64M -Xmx256M build/libs/account-1.0.0-SNAPSHOT.jar In my Ubuntu System Monitor, the jar memory ...
prime's user avatar
  • 839
0 votes
1 answer
168 views

Lets have a simple code snippet import java.invoke.VarHandle.fullFence; ... int x = 42; int y = 42; ... x = 1; fullFence(); x = 0; y = x; fullFence(); //another ...
Turin's user avatar
  • 2,311
0 votes
2 answers
203 views

Now, before some zealot quotes Knuth forgetting what he spent his life on - the question has a mostly educational purpose, as I struggle to understand memory barriers. Lets assume: public class Var&...
Turin's user avatar
  • 2,311
1 vote
1 answer
349 views

The process of creation of some of Scala immutable collections, most notably List, is mutable. In 2.13 the concurrency issues were addressed by adding a release fence basically to every builder. A ...
Turin's user avatar
  • 2,311
0 votes
2 answers
187 views

I was reading an interesting article about the memory barriers and their role in JVM concurrency, and the example implementation of Dekker's algorithm took my attention volatile boolean ...
George's user avatar
  • 3
5 votes
4 answers
726 views

Many programming languages today have happens-before relation and release+acquire synchronization operations. Some of these programming languages: C/C++11: happens-before, release+acquire Rust and ...
user avatar

1
2 3 4 5
9