Java package which contains utility classes commonly useful in concurrent programming. This package includes a few small standardized extensible frameworks, as well as some classes that provide useful functionality and are otherwise tedious or difficult to implement.
0
votes
4answers
48 views
How to run a set of tasks in parallel and wait until all of them are finished with java concurrency utils?
I have N tasks, I want them to be processed in parallel with N threads.
I want to wait until all tasks are finished, store results, and then run next N tasks (and so on in a loop).
Which abstractions ...
0
votes
2answers
40 views
Concurrency: implement connection timeout in custom connection pool
I have to implement my own connection pool, and I want the connection will automatically
return to the pool after some CONNECTION_TIMEOUT. How can I achive that?
Everything that comes to mind is to ...
0
votes
1answer
15 views
CyclicBarrier code not working?
I got CyclicBarrier code from oracle page to understand it more. I modified it and now having one doubt.
Below code doesn't terminate but If I uncomment Thread.sleep condition, It works fine.
...
2
votes
2answers
35 views
Does casting a CopyOnWriteArrayList to a List cause it to lose its concurrency guaranties?
The above (title) is my main concern. And the case is
public class MyClass{
CopyOnWriteArrayList<Stuff> min;
...
public List<Stuff> get(){
return min;
}
}
Is the resulting ...
4
votes
2answers
86 views
What are the advantages of Lambda Expressions for multicore systems?
The Java Tutorials for Lambda Expressions says following:
This section discusses features included in Project Lambda, which aims
to support programming in a multicore environment by adding ...
5
votes
3answers
68 views
How atomicity is achieved in the classes defined in java.util.concurrent.atomic package?
I was going through the source code of java.util.concurrent.atomic.AtomicInteger to find out how atomicity is achieved by the atomic operations provided by the class. For instance ...
2
votes
3answers
118 views
Why in ReentrantReadAndWriteLock, the readLock() should be unlocked before writeLock.lock()?
From the ReentrantReadAndWriteLock class javadoc:
void processCachedData() {
rwl.readLock().lock();
if (!cacheValid) {
// Must release read lock before acquiring write lock
5: ...
1
vote
3answers
42 views
ForkJoinPool stalls during invokeAll/join
I try to use a ForkJoinPool to parallelize my CPU intensive calculations.
My understanding of a ForkJoinPool is, that it continues to work as long as any task is available to be executed. ...
0
votes
1answer
31 views
Java fork join issue
I am learning fork-join technique in java and have written the following program. I am running a for loop (5 times) and I want to run the contents of the for loop in separate threads. This is ...
0
votes
3answers
55 views
The concurrent implementation of a publisher/subscriber pattern
I want to implement a variety of of a publisher/subscriber pattern using Java and currently running out of ideas.
There is 1 publisher and N subscribers, the publisher publish objects then each ...
5
votes
3answers
79 views
How to implement consumer-producer with multiple consumers and multiple queues
Assume there are 1 producer P and 2 consumers C1 and C2. And there are 2 queues Q1 and Q2, both with a specific capacity.
P will produce items and put it into Q1 and Q2 alternately. Item is produced ...
1
vote
2answers
33 views
Ordered (natural insertion order) and threadsafe Java Map
I have a legacy application in which they are using a ConcurrentHashMap. Now as we know that concurrentHasMap is unordered, but reading objects as they were originally inserted is a requirement. The ...
3
votes
1answer
71 views
Per-key blocking Map in Java
I'm dealing with some third-party library code that involves creating expensive objects and caching them in a Map. The existing implementation is something like
lock.lock()
try {
Foo result = ...
1
vote
1answer
25 views
Updating Array elemets with out blocking entire array
Which Java Concurrent collection provide Array element level locking or atomic updation of Array elements. I do not want to lock entire array. there is 99% read operations and only 1% write operations ...
0
votes
1answer
68 views
How to compare AtomicBoolean with boolean value in java
I'm trying to deploy TTAS in a multi-threading application in java, using this code:
AtomicBoolean state= new AtomicBoolean(false);
void lock(){
while(true)
{
while(state.get())
{
...
1
vote
1answer
48 views
How is consistency maintained for multiple copies of variables that is declared as a ThreadLocal?
As far as I understand ThreadLocal variables maintain a separate copy of the variable for each thread. This variable whose multiple copies are maintained is essentially a shared variable. So what does ...
1
vote
1answer
58 views
Java BlockingQueue cause threads wait unnecessarily.
I'm using BlockingQueue(LinkedBlockingQueue) to synchronise data among several threads. Please see the picture below.
The main thread is a producer which produces objects and then put them into the ...
0
votes
2answers
41 views
PriorityQueue and PriorityBlockingQueue
which one should I choose over another among these programs and why? Generally the question is why should I choose to use PriorityBlockingQueue over PriorityQueue.
PriorityBlockingQueue
import ...
0
votes
1answer
50 views
Java Executor not working on JdbcTemplate
I am trying to execute a query with a jdbcTemplate using an executor object but for some reason the program doesn't go inside the jdbcTemplate.
ExecutorService executor = ...
0
votes
1answer
107 views
Extract and Insert concurrently into database using JdbcTemplate and BlockingQueue
I am extracting thousands of rows from one database table and inserting into another database table. I don't want to load all the records into memory and then insert into the other database.
Because ...
0
votes
2answers
50 views
how to call async class more than once in an activity?
I have AsyncClass in my activity, which is used to upload data to server on a button click. If uploads is success. I am setting IsUploaded=true and updating that value in my local database for the ...
3
votes
4answers
87 views
Java's ExecutorService performance
I have a main thread which dispatches jobs to a thread pool. I'm using Java's Executor framework.
From the profiler (VirtualVM) I can see each thread's activity: I can see that the main thread is ...
3
votes
3answers
63 views
Java synchronized thread
Not sure whether this D class thread is correct. Is there a race condition, is i supposed to be in a synchronized block when accessed? What if D is an outer class, and the A instance was passed to a D ...
0
votes
1answer
40 views
In ConcurrentHashMap, why don't use ReentrantReadWriteLock in place of ReentrantLock on segment
Since the ConcurrentHashMap can't 100% secure consistency on the write operation (i.e. size()), using the ReentrantReadWriteLock(or it's derived class by customizing) instead can improve the ...
0
votes
2answers
60 views
Reinitialize fix delay in ScheduledExecutorService
As per my requirement, I have to execute some particular code after certain period of time. To do the same I have chose ScheduledExecutorService.scheduleWithFixedDelay(runnable, 0, 5, ...
2
votes
2answers
70 views
Impossible (?): NullPointerException on ConcurrentLinkedQueue.size()
I'm getting this NPE on IBM JVM, 1.6:
java.lang.NullPointerException at
java.util.concurrent.ConcurrentLinkedQueue.first(ConcurrentLinkedQueue.java:274) at
...
1
vote
1answer
90 views
Executors - Need for a LinkedBlockingQueue
When we talk about the processing of asynchronous events using an Executors service, why does creating a new fixed thread pool, involve the use of LinkedBlockingQueue ? The events which are arriving ...
0
votes
3answers
74 views
Memory Consistency - happens-before relationship in Java
While Reading java docs on Memory Consistency errors. I find points related to two actions that creates happen - before relationship.
When a statement invokes Thread.start, every statement that has ...
3
votes
2answers
96 views
Least value concurrent map
I require an implementation of a map,
that supports concurrency, and only stores the least/most value added (depending on the comparator).
Would the following code work?
class ...
0
votes
1answer
40 views
Daemon threads in ForkJoinPool
According to Java Doc 7:
Because ForkJoinPool uses threads in daemon mode, there is typically
no need to explicitly shutdown such a pool upon program exit
Are there no other advantages?
Is a ...