java.util.concurrent Questions
4
Solved
I have a scenario where I have to execute 5 thread asynchronously for the same callable. As far as I understand, there are two options:
1) using submit(Callable)
ExecutorService executorService =...
Englut asked 23/12, 2015 at 17:10
1
I'm creating an user event system using JDK 9 Flow API, so I have a room (which implements Flow.Subscriber<Notification>), it may have many users and each user can offer (dispatch) updates at...
Ventura asked 1/3, 2018 at 19:29
3
Solved
I have a list of work-unit and I want to process them in parallel. Unit work is 8-15 seconds each, fully computational time, no I/O blocking. What I want to achieve is to have an ExecutorService th...
Kiangsu asked 15/12, 2020 at 11:16
2
Solved
I am trying to use TimeUnit in Java but it just sends me errors.
This is how I wrote it:
import java.util.concurrent.TimeUnit ;
public class Anything {
public static void main( String[] args ) {...
Gusgusba asked 8/12, 2017 at 15:43
1
Solved
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 lat...
Trajan asked 26/11, 2023 at 10:34
3
Solved
According to Javadoc:
A CountDownLatch is initialized with a given count. The await methods block until the current count reaches zero.
That means in the below code, since I initialized the CountD...
Modicum asked 23/3, 2012 at 3:2
11
Solved
java.util.concurrent API provides a class called as Lock, which would basically serialize the control in order to access the critical resource. It gives method such as park() and unpark().
We can...
Codfish asked 17/11, 2010 at 5:13
2
Solved
How do you know that the function computeIfAbsent of a ConcurrentHashMap had to call the given generator method ("mappingFunction")?
From the Javadoc I believe it returns the new value, if one was ...
Daile asked 22/9, 2015 at 14:35
4
Solved
I have 2 methods that have different return types that I want to run at the same time. Here is my code:
public void method(int id) {
final CompletableFuture<List<FooA>> fooACF = Compl...
Farrier asked 20/11, 2017 at 21:38
1
I found UNSAFE.compareAndSwapObject very strange when reading the JDK ConcurrentLinkedQueue. (class CLQ is copy from ConcurrentLinkedQueue for easy debug...)
When I offer the first item to Concurr...
Anyone asked 27/2, 2014 at 17:36
2
I'm tracking execution of a task with standard Future object. There are the following valid states of that task (as I see in Guava code of AbstractFuture class):
Running;
Completing;
Completed su...
Burrow asked 23/6, 2014 at 15:58
5
Solved
I have a situation for which I am having troubles to find a clean solution. I'll try to explain as detailed as possible.
I have a tree-like structure:
NODE A
NODE A.1
NODE A.2
NODE A.2.a
NODE...
Wolk asked 23/8, 2017 at 12:36
5
Solved
I am confused with the following.
I know, if I use the schedule method from the ScheduledThreadPoolExecutor class:
ScheduledFuture<?> scheduledFuture =
scheduledThreadPoolExecutor.schedule...
Outage asked 31/7, 2014 at 0:16
6
Solved
I have multiple consumer threads waiting on a CountDownLatch of size 1 using await(). I have a single producer thread that calls countDown() when it successfully finishes.
This works great when th...
Seemly asked 4/5, 2012 at 18:1
6
Solved
I need a map with the following requirements :
It should be highly concurrent. The put(), get() and remove() methods may be called by multiple threads simultaneously.
It should be of fixed size....
Amass asked 5/11, 2014 at 13:28
2
Solved
Today I experimented with the "new" CompletableFuture from Java 8 and found myself confused when I didn't find a runAsync(Callable) method.
I can do it myself like shown below, but why is this (to ...
Boxwood asked 31/5, 2015 at 16:24
5
Solved
Here:
An object is considered to be completely initialized when its constructor finishes. A thread that can only see a reference to an object after that object has been completely initialized is g...
Ewing asked 19/10, 2021 at 22:25
5
Solved
What is the difference between AtomicBoolean.set(flag) and AtomicBoolean.compareAndSet(!flag, flag)?
I wonder if there is any difference(or possible side effects) between calling:
AtomicBoolean.set(true)
and
AtomicBoolean.compareAndset(false, true)
The JavaDoc of AtomicBoolean#set states:
...
Haematogenous asked 13/11, 2012 at 15:38
2
Solved
I see that the above annotations are used extensively in the book JCIP . I think it is really useful because even in the absence of proper documentation it says some things about the synchronizatio...
Epigram asked 6/7, 2012 at 12:34
7
Solved
Can the following piece of code be rewritten w/o using Collections.synchronizedMap() yet maintaining correctness at concurrency?
Collections.synchronizedMap(new WeakHashMap<Class, Object>()...
Spiritism asked 13/2, 2010 at 0:16
1
In the transfer method,the condition for judging the termination of the expansion (or the helping transfer threads finish) is if (i < 0 || i >= n || i + n >= nextn) {. I know i < 0 this...
Illative asked 26/8, 2020 at 11:52
5
I've noticed that some of the commands in my application fail with
Caused by: ! com.netflix.hystrix.exception.HystrixRuntimeException: GetAPICommand timed-out and no fallback available.
out: ! at...
Tonometer asked 9/12, 2014 at 9:34
3
Solved
I had a question while studying CompletableFuture. The get()/join() methods are blocking calls. What if I don't call either of them?
This code calls get():
// Case 1 - Use get()
CompletableFuture.r...
Malodorous asked 7/1, 2021 at 1:40
3
Solved
I want to implement a simple comparator between two Objects, whose only requirements are that
it is a valid comparator (i.e. defines a linear order on all objects) and
.compare will return 0 if an...
Kohinoor asked 21/12, 2020 at 8:26
2
Solved
I'm using a ScheduledExecutorService and submitting a task like that:
future = scheduledExecutorService.schedule(myRunnableTask, delay, timeunit)
However a certain event might occur after indefi...
Flessel asked 30/4, 2019 at 14:15
1 Next >
© 2022 - 2025 — McMap. All rights reserved.