Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

1 vote
1 answer
88 views

Java concurrency problem by multi-thread not occured and automatically synchronized

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
-1 votes
0 answers
19 views

Exception in HostObject::get for prop 'UIManager': java.util.ConcurrentModificationException - React Native

In our react native app (developed via expo with a custom dev client) we are encountering a problem. Some users have told us that very often the app crashes the first time it is launched on Android. ...
Niccolò Caselli's user avatar
1 vote
1 answer
58 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 ....
user avatar
1 vote
1 answer
59 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 ...
Mustafa Abudalu's user avatar
-2 votes
1 answer
105 views

Only one of my threads executes when trying to use a Semaphore [closed]

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
-2 votes
1 answer
27 views

Idiom for 2 argument version of Condition#await(long, TimeUnit)

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
87 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 { ...
Abe's user avatar
  • 8,931
3 votes
1 answer
123 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 ...
nluk's user avatar
  • 714
0 votes
2 answers
109 views

How to ensure an unique item/object is picked from the collection in multi-threading scenario?

I have a collection of string values available. I thought of using CopyOnwriteArrayList or ConcurrentLinkedQueue initially. But, when I run my code, I see that same string values are picked by one ...
Rahul Raj's user avatar
  • 3,359
0 votes
1 answer
150 views

How to determine coreThreadSize if having multiple threadpools in application

There are a lot of online resources showing how to determine best coreThreadSize when working with a SINGLE threadpool.Brian Goetz in his famous book "Java Concurrency in Practice" ...
Drex's user avatar
  • 3,711
0 votes
1 answer
235 views

Apache nifi concurrent task

How Nifi uses concurrency framework to achieve parallelism. nifi concurrent task If I assign concurrent task to 5. At a time five flowfile will be processed by nifi processor,then onTrigger is called ...
Sathish 's user avatar
1 vote
1 answer
78 views

How to maintain atomicity with ConcurrentHashMap get and put methods?

In a multi-threaded environment, I am performing get and put operations on a ConcurrentHashMap implementation. However, the results are un-expected. Please find below code and output. import java.util....
Pushpak's user avatar
  • 159
2 votes
2 answers
155 views

ComputeIfAbsent wrong map size

I have tried below code in order to have a unique id for each jj. As far as I know, computeIfAbsent is thread-safe but: public static void main(String[] args) throws InterruptedException { ...
Ahmad Darwich's user avatar
0 votes
0 answers
62 views

Avoid cost of volatile value in AtomicReference

Thread 1 -> Compute a value MyObject and store in AtomicReference< MyObject>> Thread 2 -> Would sometimes need the value of MyObject stored by Thread 1 Looking at AtomicReference::set ...
Novice User's user avatar
  • 3,764
0 votes
1 answer
61 views

Why ForkJoinTask.join() call rather block the thread instead of stealing the work as expected from work stealing mechanism

I have a recursive task which splits asymmetrically. Instead of splitting in halves it rather bites a pice of work it can execute and forks the rest of work. Such scenario does not get paralleled as ...
Alex Gal's user avatar

15 30 50 per page
1
2 3 4 5
35