Skip to main content
Stack Overflow for Teams is now Stack Internal: See how we’re powering the human intelligence layer of enterprise AI. Read more >
Filter by
Sorted by
Tagged with
2 votes
1 answer
65 views

Given a Java ConcurrentMap, I would like to atomically: Check if an entry is contained in the map If it is present, run an action (I'm thinkng of a BiConsumer taking the key and its value) Otherwise, ...
Danilo Piazzalunga's user avatar
3 votes
1 answer
69 views

In Java, when using scheduleAtFixedRate, is it possible for a task to execute before the ScheduledFuture returned by scheduleAtFixedRate has been assigned? For example, could the following code throw ...
Xin Zhang's user avatar
2 votes
1 answer
135 views

When working with JNI, can the native side obtain an _Atomic int32_t* given a Java AtomicInteger reference, and run C atomic functions on it (e.g. atomic_fetch_add)? We could call Java's methods (e.g. ...
anon's user avatar
  • 697
2 votes
1 answer
87 views

For a parallel Stream, the collect method has a 3-arg variant: (source: oracle documentation ) /** Parameters: supplier - a function that creates a new result container. For a parallel execution, this ...
Name Null's user avatar
  • 519
2 votes
0 answers
110 views

I'm using java.util.concurrent.ScheduledExcecutorService.scheduleAtFixedRate to execute a task periodically. I run it once every minute and it usually completes after 5 seconds, but occasionally runs ...
Joshua Davies's user avatar
0 votes
1 answer
117 views

I have a multithreaded program that both produces output via a timer and receives user input. It behaves badly when I want to type in a command such as "pause" or "stop": anything ...
iamzence's user avatar
3 votes
1 answer
87 views

I attempted to replicate the experiment about "Release/acquire" from Doug Lea‘s blog on j9mm (https://gee.cs.oswego.edu/dl/html/j9mm.html#summarysec) : volatile int ready; // Initially 0, ...
SemgHH's user avatar
  • 41
0 votes
0 answers
33 views

I have generated java protobuf class. This class has protobuf extensions also. Is it safe to modify different unrelated fields and extensions of the same protobuf builder in parallel? message ...
Capacytron's user avatar
  • 3,818
4 votes
1 answer
213 views

Im trying to create a Java App using SpringBoot 3 framework and GraphQL. I'm trying to resolve a field which depends on several dataLoaders within my App however, I seem to be running into an issue ...
maxs87's user avatar
  • 2,224
-1 votes
1 answer
58 views

I'm currently working on a concurrent implementation of multiplayer Tetris in JavaFX where each game is run on a separate Stage. Each game has its own set of inputs so you can play simultaneously as ...
Kyle Nickson's user avatar
0 votes
1 answer
78 views

Edit: I've cut down Mainboard to just the relevant function to make code shorter to read. If any additional code needs to be read to help understanding, please say I'm currently making a multiplayer ...
Kyle Nickson's user avatar
0 votes
1 answer
107 views

I need to asynchronously consume future value and then run logic X. In case of any exceptions, I also want to execute logic X. In a way, it is semantically akin to the finally block. I do not have a ...
Cagepi's user avatar
  • 329
-4 votes
1 answer
177 views

The class implementation below wraps two AtomicInteger fields. After the max=9999 value is reached, the main sequence number is expected to reset to zero. When the sequence number resets, the ...
Awan Biru's user avatar
  • 484
1 vote
2 answers
109 views

I have not used Java in a million years and trying to figure out how to differentiate between different types of Exception in CompleteableStage. Currently, I have something like below but it does not ...
r2d2's user avatar
  • 13
0 votes
3 answers
146 views

I have a problem regarding spring DefaultManagedTaskExecutor. We are deploying our SpringBoot 3.2.5 application to websphere Liberty and we are using Liberty ManagedExecutorService as external ...
David Černý's user avatar
2 votes
1 answer
534 views

The jdk 21 doc about virtual threads (hereafter "VT") (https://docs.oracle.com/en/java/javase/21/core/virtual-threads.html) is pretty clear about a synchronized block causing a thread to be ...
user2023577's user avatar
  • 2,161
0 votes
1 answer
25 views

Spring-Rabbitmq SimpleRabbitListenerContainerFactory is defined with a CustomThreadPoolExecutor. @Bean public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(final ...
indika's user avatar
  • 945
1 vote
0 answers
205 views

I have a Java process consuming upwards of 400% CPU on my server (AlmaLinux) which shouldn’t be the case. On my analysis I find multiple QTPs (Queued Thread Pools) consuming the CPU: After analysing ...
Fabio Abreu's user avatar
1 vote
2 answers
194 views

From the library I use I get ConcurrentMap. I want to obtain it's keys as Set. How to do it in thread-safe way (since Kotlin collections API is thread-unsafe)?
pixel's user avatar
  • 26.8k
0 votes
2 answers
121 views

Can this code ever lead to missed signal? If yes, then how? private Object lock = new Object(); private boolean conditionMet = false; public void waitForCondition() throws InterruptedException { ...
user1918858's user avatar
  • 1,228
0 votes
0 answers
96 views

Fine, this is most probably a silly question... Is there a way to construct a StructuredTaskScope using an ExecutorService? Any idea is welcome. Best regards Alex
Alexander Schell's user avatar
0 votes
2 answers
52 views

Scenario I am creating some records in a system using three requests of its API. In the first request I need to send and Id which for testing and tracking purposes I am using a consecutive number ...
Ricker Silva's user avatar
  • 1,175
1 vote
0 answers
62 views

I'm trying to write an in-memory implementation of the load balancer that will have a get() method returning the instances in a round-robin pattern, I need it to run properly in a concurrent ...
Anonymous9991's user avatar
2 votes
0 answers
75 views

Basic: // this.a is a shared variable. AtomicInteger a = this.a; int x = a.get(); In a multi-threaded condition, we cannot ensure that x is 1 because some other thread may call something like a....
SpreadZhao's user avatar
-1 votes
2 answers
236 views

I would like to conditionally and atomically update (or set if the current is empty) an AtomicReference based on a Predicate on the current value. I was hoping that something like this existed: /** * ...
peterh's user avatar
  • 19.5k
1 vote
1 answer
123 views

I’m trying to test a multi-threaded concurrency problem. What I expected is that the result should be less than 0 (not always but sometimes), because it is not synchronized. Notice the pair of println ...
MangKyu's user avatar
  • 51
0 votes
1 answer
117 views

It's my first post and I'm a beginner with CompletableFuture and I want to test exceptions (InterruptedException and TimeoutException) when I use CompletableFuture.get(). My code: CompletableFuture<...
Marsei's user avatar
  • 3
1 vote
2 answers
2k views

In java 17, we are seeing that a lot more threads are getting created (although not concurrently executing) as compared to older java version (java 8 in my case). While thread itself may not be a huge ...
best wishes's user avatar
  • 6,794
1 vote
1 answer
69 views

During a course on concurrent programming, I've run into this sample code: @Test void promiseTestCompose2() throws Exception { CompletableFuture<Integer> future1 = CompletableFuture ....
user avatar
0 votes
2 answers
685 views

I'm learning java concurrency under the hood and I've read some java article and videos regarding multi threading and concurrency and just can't seem to put them all together Here is the gist of what ...
javanoob's user avatar
0 votes
0 answers
41 views

I was trying to do some experminet with CopyOnWriteArrayList and found that when 2 threads are concurrently modifying same CopyOnWriteArrayList object, the final result changes in different run. ...
tatushar3's user avatar
  • 111
0 votes
0 answers
47 views

I am trying to create a class which sends and receives commands via serial port. Sadly the whenComplete is never called. I also tried to log the response and in the callback it is correct but when I ...
perotom's user avatar
  • 933
1 vote
1 answer
193 views

I'm trying to figure out, how the java.util.concurrent.DelayQueue works in the multithreaded environment. I see that this data structure uses ReentrantLock internally, and it is acquired at the ...
Fedorucho's user avatar
-4 votes
1 answer
93 views

Here is my code for the problem which works fine, however, when I change the while statement right under synchronized statement, it seems any thread that get the lock after notifyall() just continue ...
cokkiePlay's user avatar
1 vote
1 answer
167 views

I’m developing a custom caching mechanism for my Java application to cache objects that are expensive to create (e.g., database connections). The idea is to allow concurrent access to the cache while ...
Mustafa Abudalu's user avatar
-1 votes
1 answer
233 views

Need to know the insights of the complete future task without an executor. Here is my sample code CompletableFuture.runAsync(() -> { dosomething(); }); How is this task assigned to the thread? ...
div's user avatar
  • 1
2 votes
1 answer
1k views

I have a REST endpoint in springboot which calls an external api async multiple using CompleteableFuture. The external api is called using resttemplate in Completeablefuture.supplyAsync(() => ...
Aditi's user avatar
  • 65
0 votes
0 answers
310 views

I have an async application. By executing for example the async method getTest() I never get the full strack trace caused the error: CompletableFuture<Test> test = myAdapter.getTest(); test....
Thomas's user avatar
  • 277
0 votes
0 answers
38 views

Help me understand the work with the database, on the 3-5 iteration, data is incorrectly written to the database in the lemma table, the site is correctly recorded, the page is also, but when lemma ...
Ivan Kazantsev's user avatar
-2 votes
1 answer
120 views

To my understanding, java.util.concurrent.Semaphore allows me to specify how many threads can use a resource at once. A thread can use Semaphore.acquireUninterruptibly() to consume the limited number ...
davidalayachew's user avatar
-1 votes
1 answer
1k views

I'm trying to play with async java in my intellij local. My intention is that i will call calucalateAsync() method from main method and then put the debug point on System.out.println("calculate ...
vinter's user avatar
  • 520
17 votes
1 answer
30k views

I have an issue when I am trying to use TimeUnit class from java.util.concurrent. It happens with Oracle JDK 21.0.1 (configurations are below) + IntelliJ IDEA 2023.1.5 (Community Edition) - the latest ...
pragmatic's user avatar
  • 511
0 votes
1 answer
76 views

I have a use-case where I need to hit an endpoint to fetch some data. The endpoint takes start-date-time and end-date-time as params and has a limitation that the duration between them can only be <...
mysteryFruit's user avatar
0 votes
0 answers
43 views

Background I'm learning Java Socket on my own. I created a Socket Server and Client to run on localhost. Server uses a fixed-size threadpool of size 20 to handle connections. Client creates 50 ...
Wanda's user avatar
  • 1
0 votes
2 answers
369 views

In my Android app I want to use java.util.concurrent tools to make operations that return value (for educational purposes). I read that CompletableFuture can be used for this. I made a project where I ...
faritowich's user avatar
-2 votes
1 answer
38 views

What's the idiomatic way of handling spurious wakeups when using the 2 argument version of Condition#await(long, TimeUnit) I understand the zero argument version: import java.util.concurrent.Executors;...
David O'Loughlin's user avatar
0 votes
1 answer
127 views

Consider the following code class Test { public void method1() { CompletableFuture<String> future = helloFuture(); assertEquals("done", future.get()); } } class Service { ...
Abe's user avatar
  • 9,141
0 votes
1 answer
71 views

Is Field public void set(Object obj, Object value) thread-safe when using Java reflection? If it's not thread-safe, how can the atomicity of set be ensured? Write rarely and read frequently, reads and ...
xiao chen's user avatar
3 votes
1 answer
146 views

I have overridden the execute method for java.util.concurrent.Executor in ThreadPoolExecutor implementation. The new implementation just decorates the runnable and then calls the original execute. The ...
nluk's user avatar
  • 754
0 votes
1 answer
131 views

I am trying to understand the implementation of CHM in Java. Two fields are used when resizing operations are taking place: baseCount sumCount() function baseCount is described as : / ** * ...
ng.newbie's user avatar
  • 3,312

1
2 3 4 5
29