1,435 questions
2
votes
1
answer
71
views
ConcurrentMap: atomically check if a value if present, and then mutate it with a consumer
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, ...
2
votes
1
answer
135
views
Does the JNI provide direct access to _Atomic values for the respective Java Atomic classes?
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. ...
2
votes
0
answers
110
views
Long term behavior of ScheduledExecutorService.scheduleAtFixedRate when tasks run too long
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 ...
3
votes
1
answer
87
views
Can not reproduce experiment about RA mode of J9mm
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, ...
4
votes
1
answer
213
views
thenCompose hangs/timeout web graphql application
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 ...
0
votes
1
answer
78
views
Is there a way to switch the focus window upon a key press in JavaFX
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 ...
-4
votes
1
answer
177
views
How to safely reset AtomicInteger value in highly multithreaded environment? [closed]
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 ...
0
votes
3
answers
148
views
Spring 6.2 DefaultManagedTaskExecutor throws java.lang.UnsupportedOperationException: isShutdown when rejecting tasks
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 ...
0
votes
1
answer
26
views
afterExecute method is not invoked defined in CustomThreadPoolExecutor that is passed to RabbitMQ Spring SimpleRabbitListenerContainerFactory
Spring-Rabbitmq SimpleRabbitListenerContainerFactory is defined with a CustomThreadPoolExecutor.
@Bean
public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(final ...
1
vote
2
answers
195
views
How to interact with concurrent collections from Kotlin?
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)?
0
votes
0
answers
96
views
Java 21 Create StructuredTaskScope from ExecutorService
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
1
vote
0
answers
62
views
Concurrent round robin implementation fails
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 ...
-1
votes
2
answers
239
views
Conditionally set AtomicReference
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:
/**
* ...
0
votes
1
answer
117
views
Unit test CompletableFuture exceptions
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<...
1
vote
1
answer
69
views
Is CompletableFuture.supplyAsync() redundant in case it does not modify the incoming value?
During a course on concurrent programming, I've run into this sample code:
@Test
void promiseTestCompose2() throws Exception {
CompletableFuture<Integer> future1 = CompletableFuture
....
0
votes
0
answers
41
views
Does CopyOnWriteArrayList can result inRace Condition when modified by 2 or more Threads in Parallel
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.
...
1
vote
1
answer
194
views
Why calling take() method Java DelayQueue doesn't block the whole data structure for all threads?
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 ...
1
vote
1
answer
167
views
Issues with Concurrent Execution and Synchronization in a Custom Java Caching Mechanism
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 ...
2
votes
1
answer
1k
views
TraceId and Span are empty in async task logs
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(() => ...
0
votes
0
answers
38
views
Data loss when adding a record to the database
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 ...
-1
votes
1
answer
1k
views
Why executor service submitted task is not executing the task async?
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 ...
0
votes
1
answer
76
views
What's wrong with my function for making async calls to an endpoint and collecting responses?
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 <...
0
votes
2
answers
369
views
Using Future blocks UI in application
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 ...
0
votes
1
answer
127
views
How does the jvm return a Future object reference before the asynchronous method has completed
Consider the following code
class Test {
public void method1() {
CompletableFuture<String> future = helloFuture();
assertEquals("done", future.get());
}
}
class Service {
...
3
votes
1
answer
146
views
Why does the 'execute' method of ExecutorService in applyAsync run on main thread sometimes
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 ...