Questions tagged [java.util.concurrent]

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.

java.util.concurrent is a core 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.

Main components include:

  • Executors
  • Queues
  • Timing
  • Synchronizers, Semaphores, CountDownLatch
  • Concurrent Collections

More information is available at the JavaDoc description

1396 questions
0
votes
2 answers

Exchanger Vs CountDownLatch

I was wondering if anyone has used the java.util.concurrent.Exchanger class. According to java docs an Exchanger can be used to share some data between a pair for threads. The below sample is a typical usecase of reading and writing data and…
Tatha
  • 1,253
  • 2
  • 24
  • 42
0
votes
1 answer

Best data structure in Java when using HashSet as a cache

My use case is this: I need to cache a set of strings for frequent read access. The cache is updated by a daemon thread periodically. Moreover, the cache element will never get updated individually, it would always be set.clear();set.addAll(List)I'm…
bohanl
  • 1,885
  • 4
  • 17
  • 33
0
votes
1 answer

Long running httprequest with springMVC

To handle long the running process we are using SpringMVC DeferredResult to send the data to the browser, but after certain period of time the browser returns no data received, while the process is still running in the back end. it works fine in…
Arun Kishore
  • 119
  • 3
  • 12
0
votes
1 answer

java model client server architecture with lock on resources

I have to develop a client server architecture with Java (server side), but I need some advice. Situation: a server that exposes an action decrementValue the server has a variable called Value = integer value some clients can send a decrementValue…
michele
  • 26,348
  • 30
  • 111
  • 168
0
votes
1 answer

parallel file downloads using nio without creating threads per file download

I have tried a program which download files parallely using java.nio by creating a thread per file download. package com.java.tftp.nio; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import…
Shriram
  • 4,343
  • 8
  • 37
  • 64
0
votes
2 answers

What is the best approach for loading data from DB by multiple threads

I have some data in database in parent child relation, where my table is actually representing a forest of tree data structure. And the table structure is like: row1 parent: null row2 parent:row1 row3 parent:row2 row4 parent:row1 Now when I am…
Arpan Das
  • 1,015
  • 3
  • 24
  • 57
0
votes
2 answers

How to figure out N threads I need in a parallel execution context?

I'm working in a redelivery system. This system attempt to execute an action, if the action fails, it try to execute again two times with an interval of five minutes, so I use the ExecutorService implementation to perform the first execution and…
irobson
  • 825
  • 8
  • 20
0
votes
1 answer

handling concurrency for last item in inventory

We've 1 book left in the inventory. and two people are trying to get the same book ( say person x and person y ). Person x has added book to the cart and about to make payment and person y has also added book to the cart. How would you solve this…
dead programmer
  • 4,223
  • 9
  • 46
  • 77
0
votes
3 answers

Serialized access to Collection with the use of ConcurrentLinkedQueue

I have the following question concerning Java 7 ConcurrentLinkedQueue. Let us assume that I have the following class: public class Blah { private ConcurrentLinkedQueue queue; public Blah() { queue = new…
nick.katsip
  • 868
  • 3
  • 12
  • 32
0
votes
1 answer

Run a ScheduledExecutorService periodically or just once based on condition

I have a specific task which has to be executed periodically, or just once based on a condition. I am using the following approach: Runnable r = new Runnable() { public void run() { //Execute task } …
abksrv
  • 1,347
  • 1
  • 15
  • 34
0
votes
1 answer

Using java futures without requiring local mutable state

I've written some code that essentially is responsible for orchestrating a number of API's in sequence through a library method I provide to my clients called "orchestrate" (yes I know so original). What sits behind this orchestrate method is…
BSJ
  • 1,185
  • 2
  • 10
  • 15
0
votes
0 answers

Running multiple threads using executor service takes more time than running single thread

I am using below code to process the big CSV file, it will split the CSV for every 2000 records and schedules a thread to process the 2000 records, at the end, after all threads finishes it execution, the future is taken. I am facing the following…
0
votes
3 answers

AtomicBoolean, set flag once, necessary? Might a static boolean be ok?

I am setting a flag which is set once by any thread that get to set it. All other threads will at various time, pretty often read this flag repeateadly. Right now I am using an AtomicBoolean, which works fine, but I know that if it is queried quite…
mjs
  • 21,431
  • 31
  • 118
  • 200
0
votes
1 answer

ThreadPoolExecutor and ArrayBlockingQueue

Excuse me for my bad english. When the number of threads in the pool to rise above 10, the the task will be placed in ArrayBlockingQueue . But if the task Callable? Constructor ThreadPoolExecutor not accept ArrayBlockingQueue typed as Callable.…
0
votes
1 answer

ExecutorService invokeAll deadlock

While writing a skeleton program for ExecutorService invokeAll I came across an interesting scenario which seems created a deadlock. Couldn't figure out exactly why this is happening. Here is the program which instantiates 3 tasks and calls…
kosa
  • 65,990
  • 13
  • 130
  • 167