3
votes
3answers
75 views

Scalable way to access every element of ConcurrentHashMap<Element, Boolean> exactly once

I have 32 machine threads and one ConcurrentHashMap<Key,Value> map, which contains a lot of keys. Key has defined a public method visit(). I want to visit() every element of map exactly once ...
1
vote
6answers
63 views

Java threading and outputstream printinng issue

Hi I am just trying my hands with threading, Just a Request its not a homework or anything its just testing of my understanding of the subject, so those who doesnt like it please dont close it there ...
1
vote
0answers
54 views

Resettable timer performance in Java

When profiling my app, I found a source of frequent allocations... I am utilizing multiple timers to check for timeouts (~2ms, varies with app state). According to this SO answer, ...
0
votes
2answers
73 views

How to concurrently modify a Vector

I have to ensure while iterating the Vector; there is no update on that Vector to avoid ConcurrentModificationException. I can use concurrent collection. But i just want to give a try on Vector. Below ...
1
vote
0answers
32 views

Working with Executors and Handlers within a Android Service

First of all: I am a multi-threading newbie. So forgive my stupidity on this matter :) I want to accomplish the following: Startup an Android Service and initialize/start several threads next to ...
0
votes
4answers
84 views

If I simply need to guarantee `happens-before` relation, and not atomicity, should I use a concurrent class or a synchronized block?

I am developing a pool mechanism. Objects in the pool will be used by different threads. Thus I need to guarantee that there will be a happens-before relation when accessing non-final attributes of ...
6
votes
4answers
82 views

Concurrent request processing in Java with constraints

Suppose I need to process requests of 3 types: A, B, and C as follows: Requests are processed concurrently. There are at most K (<= 3) requests to be processed concurrently at the same time. ...
1
vote
2answers
79 views

Non-blocking method to start several threads and run a callabck on the parent thread when all children have finished

The main thing is that the callback should be on the PARENT thread and not called from the task, which is finishing the job (e.g. NOT like ThreadPoolExecutor's afterExecute() hook). I'd like to have ...
0
votes
1answer
74 views

How to read data concurrently using java?

I have a method which takes a string as input and returns data from the DB based on the input string. I have an array of strings and I am currently passing each string as input and looping over the ...
1
vote
2answers
45 views

Reuse of a worker instance to handle several tasks

I have an application for web testing (based on Selenium but this should not matter much here) which executes quite a number of test cases successively. It takes a couple of hours to complete and the ...
2
votes
2answers
105 views

Will the use of volatile & atomic always ensures thread safety

I get mixed answer whenever I look for concurrent access , JCIP book I have already ordered and is on the way , but I want to nail this concurrency basics of mine , here is my scenario I have 3 ...
1
vote
1answer
38 views

What is meant by cpu slack?

The following is an excerpt from the book Java Concurrency in Practice, Chapter 12.2 Testing for Performance where the author talks about throughput of a bounded buffer implementation. Figure 12.1 ...
3
votes
1answer
92 views

Why not use a pseudo random number generator to produce test data?

From the book Java Concurrency in Practice , Chapter 12.1 Testing for correctness, specifically in sub-section 12.1.3 Testing safety(where the author wants to set up test cases for testing data-race ...
3
votes
3answers
85 views

Awaiting multiple instances of CountDownLatch in container

I wrote a class CountDownLatchContainer it has a await() method, that waits on all CountDownLatches. Everything is working fine. public final class CountDownLatchContainer { private final ...
0
votes
1answer
49 views

Do i need to call Platform.runLater for updating UI if i'm working on JavaFX Application Thread

Do i need to create a new Runnable object and run Platform.runLater if i'm still working on JavaFX Application Thread for updating UI. For example, i need to update a Text object which is imported in ...
1
vote
3answers
148 views

Print RED BLUE GREEN in order using System.out.print

public class CyclicBar { private final static CyclicBarrier cb = new CyclicBarrier(3, new Runnable() { @Override public void run() { ...
1
vote
0answers
102 views

Concurrent collection

I have a bunch of threads, each which create a lot of objects. As each object is created I need to check a collection of existing objects to make sure make sure an equal object hasn't already been ...
1
vote
2answers
93 views

Does a Synchronous Queue create a thread on each offer/put?

I can not understand how the Synchronous Queue works. I understand that the idea is that the handover of tasks is to threads directly but the constructor does not have a bound e.g max number of ...
3
votes
1answer
83 views

Trying to understand the mechanics of a synchronous queue

I was trying to read the implementation of Synchronous Queue It is not so straightforward for me. It seems to be using a linked list where each node is associated with a thread. And the core part uses ...
0
votes
3answers
102 views

Do callable executes sequentially?

Whenever i run my program implementing callable, i get the output in a sequential form. Like, here is my program : package com.handson; import java.util.concurrent.ArrayBlockingQueue; import ...
1
vote
2answers
51 views

How does the Exchanger supports GC-less Java?

While reading about concurrent api of java, i came to know about Exchanger class. From Java docs, "A synchronization point at which threads can pair and swap elements within pairs. Each thread ...
1
vote
1answer
112 views

Is a ConcurrentHashSet required if threads are using different keys?

Suppose I have a hash set of request IDs that I've sent from a client to a server. The server's response returns the request ID that I sent, which I can then remove from the hash set. This will be ...
0
votes
2answers
61 views

Non volatile status flag in multi-threaded code

I am a novice when it comes to concurrency and unsure of myself when spotting issues, I was looking through a fairly established code base and found the following code (edited for brevity) which I ...
0
votes
2answers
59 views

Best way to code for Java 7 task required other task to finish first

I have one task that I start off immediately, various executors that run, but then I have a final task that must not run until the the first task has finished. I am some knowledge of concurrency, but ...
1
vote
4answers
168 views

How do I create a new instance of thread multiple times in same program

I am a newbie please forgive me if I am not clear with what I want. I have a java app which inserts into 2 mysql tables upon clicking submit, one is the on the local machine and other on the web ...
1
vote
3answers
365 views

Java multithreading issue - Consumer/Producer pattern

Have tried to resolve this issue but it is proving difficult. I have two threads, one is a producer, and the other a consumer. All in separate classes. The two threads run independently. The ...
-1
votes
1answer
64 views

Java: Synchronizing clearing of a map while another thread could be writing into it

I have a code like this: public class SomeClass { private ScheduledExecutorService executor; private ScheduledFuture<?> future; private Set<String> keys; private ...
2
votes
1answer
89 views

Timeout while waiting for a batch of Futures to complete?

I have a set of Futures created by submitting Callables to an Executor. Pseudo code: for all tasks futures.add(executor.submit(new callable(task))) Now I'd like to get all futures waiting at most ...
0
votes
2answers
55 views

How to cancel associated Runnables when CountDownLatch.await() is interrupted

I'm using a java.util.concurrent.CountDownLatch object (latch) to control a set of Runnables which get executed via a thread pool (which could also be executing other Runnables). In certain (and ...
0
votes
4answers
128 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
85 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 ...
2
votes
2answers
66 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 ...
5
votes
3answers
132 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
179 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: ...
0
votes
1answer
123 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
253 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
179 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 ...
3
votes
1answer
329 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
110 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 ...
3
votes
4answers
286 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 ...
1
vote
2answers
618 views

Need simple explanation how “lock striping” works with ConcurrentHashMap

According to Java Concurrency in Practice, chapter 11.4.3 says: Lock splitting can sometimes be extended to partition locking on a variablesized set of independent objects, in which case it is ...
1
vote
4answers
186 views

What´s the difference between AtomicReference<Integer> vs. AtomicInteger?

I don´t get the difference between these two: AtomicReference<Integer> atomicReference = new AtomicReference<>(1); vs. AtomicInteger atomicInteger = new AtomicInteger(1); Can someone ...
0
votes
1answer
141 views

Does using volatile to publish immutable objects are safe?

Recently I read "Java concurrency in practice" Section --> "3.4.2 Example: Using volatile to publish immutable objects". However; I can't quietly understand it. Here is the situation! Immutable ...
0
votes
2answers
622 views

ExecutorService shutdown

I am confused about the javadoc of ExecutorService#shutdown method. Aren't these contradictory statements? Initiates an orderly shutdown in which previously submitted tasks are executed, but no ...
0
votes
2answers
289 views

Parallel tasks in Java

Suppose I have a few tasks to run in parallel in Java. Each task returns either success or failure. Each task has an associated deadline. If a task does not finish by the deadline it is interrupted ...
4
votes
3answers
713 views

ExecutorService.submit(<callable>) taking more time?

I am trying to understand the utilities in java.util.concurrent package and learnt that we can submit callable objects to the ExecutorService, which returns Future, which is filled with the value ...
1
vote
2answers
91 views

How to test task performance, using multitheading?

I have some exercises, and one of them refers to concurrency. This theme is new for me, however I spent 6 hours and finally solve my problem. But my knowledge of corresponding API is poor, so I need ...
0
votes
5answers
180 views

Coordinate threads without wait/notify if possible

Besides wait/notify is there a cleaner way of notification of events among threads? E.g. if I want Thread X to notify ThreadY that something occured is there a better construct in concurrent package ...
2
votes
2answers
100 views

Design issue: is this doable only with producer/consumer?

I'm trying to increase performance of indexing my lucene files. For this, I created a worker "LuceneWorker" that does the job. Given the code below, the 'concurrent' execution becomes significantly ...
0
votes
1answer
919 views

Java Concurrent Object Pool?

I tried to integrate an external non-thread-safe library to my web project; I found out that it's too expensive to create an instance of this object for each client thread. As a result, I would like ...

15 30 50 per page