1,435 questions
1
vote
2
answers
766
views
Await completion of all ExecutorService Threads
I'm trying to get a grasp on concurrency in Java, I've made this simple code that prints the letters of the alphabet :
public static void main(String[] args) throws IOException, InterruptedException, ...
1
vote
1
answer
127
views
How does AbstractQueuedSynchronizer in JDK14 ensure memory visibility when using setPrevRelaxed?
In method acquire, node.prev is updated by node.setPrevRelaxed(t).
It actually calls unsafe.putReference which does not ensure the visibility.
final void setPrevRelaxed(Node p) { // for off-queue ...
0
votes
1
answer
2k
views
How to wait on thread until the response is available
We have following scenario where we have a class having two method and shared between multiple threads.
public class Response {
Map <String, APIResponse> requestIdToResponse = new ...
0
votes
2
answers
385
views
AtomicLong.set vs LongAccumulator.accumulate performance java?
I have a use case for high concurrent writes to an AtomicLong variable. I just need to set current epoc time in this variable. What would be the fastest way to do so?
Is LongAccumulator.accumulate a ...
0
votes
0
answers
41
views
Is using a reentrant read write lock the fastest approach?
For a stock market algorithm, I am implementing an observable pattern for handling quotes. The "observers" are a list of triggers. The issue, is that this list can change (add a trigger, ...
0
votes
2
answers
2k
views
how to kill inner threads in spring boot application
On the Springboot-based application, I am creating a thread to finish a batch job and returning back immediately. Now, I need to forcefully kill the thread in some scenarios like a timeout.
Can anyone ...
1
vote
1
answer
798
views
How to stop thread from execution if certain condition is met
Say I have a service that tries to load the data from DB, if data does not exist in DB, It tries to load from master DB and if it is not found there as well it will try to fetch from another API.
This ...
0
votes
1
answer
389
views
Java Clear CompletionService Working Queue
I am writing a program which uses a CompletionService to run threaded analyses on a bunch of different objects, where each "analysis" consists of taking in a string and doing some ...
1
vote
0
answers
309
views
Java runAsync and ForkJoin when vCPU is 2
I have a calculation heavy spring boot application that runs on an AWS t3.large EC2 instance, with 2 virtual CPUs.
I have two steps in the calculation and for the first step, I intend to use ...
1
vote
1
answer
509
views
Java concurrent collection for write intensive application - only a few reads
I'm searching various alternatives for a write intensive application when it comes to selecting a Java data structure. I know that ONE data structure could not provide a single universal solution ...
1
vote
1
answer
578
views
Last transformation not executed on CompletableFuture when completeExceptionally is called
I have following code:
public final class Start {
private static final CountDownLatch FINAL_THREAD = new CountDownLatch(1);
private static String getValue() {
System.out.println(&...
0
votes
1
answer
633
views
Consistency behaviour of ConcurrentHashMap.keySet().stream()
What consistency behaviour can I expect from this modify method with a ConcurrentHashMap?
// map is filled concurrently from multiple threads
private final ConcurrentHashMap<String, Object> map =...
1
vote
2
answers
954
views
Does ScheduledExecutorService guarantee order when pool size is one?
I have a ScheduledExecutorService that has a pool size of 1 threads.
If I schedule many tasks using that service with the same delay, is the order of scheduling preserved during the execution?
5
votes
2
answers
2k
views
Why does Java allows to initialize semaphore with negative permit?
I'm not getting the rationale behind negative permits during initialization of Semaphore (java.util.concurrent.Semaphore).
I do know that calls to release() method may eventually make Semaphore's ...
5
votes
1
answer
3k
views
Is ConcurrentHashMap compute() method thread safe?
concurrentHashMapInstance.compute("Name", (key, val) -> {
modifyValWithComplexLogic(val);
return val;
});
is modifyValWithComplexLogic(val) (and the whole compute method) ...
0
votes
1
answer
40
views
Java Blocking Q test stops executing
I have the following test code for learning purposes, in which I am trying to run a producer and a consumer threads running endlessly on a blocking Q.
For some reason which I cannot understand, the ...
0
votes
1
answer
2k
views
What's the purpose of the PriorityBlockingQueue?
I've been playing with blocking queues and PriorityQueue, and it got me thinking. I can't see a good usecase for PriorityBlockingQueue. The point of a priority queue is to sort the values put into it ...
1
vote
1
answer
261
views
PriorityBlockingQueue that ensures consecutive item sequence
I'm receiving a sequence of messages, and I want to process them in their sequential order. Each message has a sequence number. There's a pool of threads receiving them. I want to put them into a ...
3
votes
1
answer
831
views
Synchronous SubmissionPublisher
Is it possible to make Subscriber run on the same thread as the Publisher (synchronously)?
I can use CompletableFuture, but it delivers only a single result. But what if I need many results delivered ...
1
vote
1
answer
821
views
Is this ConcurrentLinkedQueue/wait/notify algorithm correct?
I know that typically for producer/consumer pairs like this, a blocking queue should be used. What I want here is only to understand better memory consistency in Java, interaction between concurrent ...
0
votes
2
answers
70
views
Why does this concurrent Java code often fail?
//Initially, I wanted to compare synchronized with Lock
public class SynchronizedVSLock {
static final Lock lock = new ReentrantLock();
static final int loopTime = 10;
static final int ...
1
vote
1
answer
353
views
getDelay(TimeUnit) associated with Delayed interface in java
To use a DelayQueue we need to implement the Delayed interface for the getDelay(TimeUnit unit) and compareTo() method and as per my understanding, the getDelay method will be called where the ...
1
vote
1
answer
420
views
use Executors.callable() within lambda
I have the following which works:
var tasks = tasks.stream(a -> (Callable<Set<FinishedTask>>) () -> call(a)).collect(Collectors.toList());
I want to change the above code to use ...
-1
votes
1
answer
1k
views
java.util.ConcurrentModificationException on replacing string in kotlin
I'm getting concurrent exception replacing string inside iterator.
fun replaceValuesInURLString(allFieldsValues: HashMap<String, UserSelectedData>, urlString: String): String {
var ...
0
votes
1
answer
279
views
How to use threadLocal for TestNG java.util.concurrent.Ex
When i run my test cases with cucumber textNg on jenkins with maven not always bu sometimes it give it error java.util.concurrent.Ex. I need to use synchronized for my methods to work properly.
I have ...