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
3 answers

java Futures execution

I was reading about Futures in Java and Promises in javascript. Below is the code I wrote as an example. My question is when does the execution of task assigned to future start? When the future is created as in below line: contentsFuture =…
Madhur Ahuja
  • 22,211
  • 14
  • 71
  • 124
0
votes
1 answer

How to handle exception from Callable

I would like to know how to handle exceptions from my Callable when I use Void as a return type. Something like this: ExecutorService executor = Executors.newSingleThreadExecutor(); executor.submit(new Callable() { @Override …
Jan Krakora
  • 2,500
  • 3
  • 25
  • 52
0
votes
0 answers

Akka run as concurrent

Recently I implement a remote actor mode in my project. I would like to know which way is concurrently running the Actors. Way 1. for(int i = 0; i < 100; i++){ Patterns.ask(Props.create(Worker.class),$someJobs, timeout); } Way 2. for(int i = 0;…
user1438980
  • 187
  • 1
  • 3
  • 13
0
votes
1 answer

Is calling Future#get(time, timeunit) directly (without checking isDone()) a bad practice?

This code runs some really cheap (in terms of time) method in a separate thread, so it's guaranteed with a 99.9999% certainty that the outer method will return successfully. If time it takes to finish the job is more than 5 seconds, I wish to…
0
votes
1 answer

ConcurrentHashMap jdk 8 Uses TreeNodes instead of List .. Why?

Hi i know the workings of ConcurrentHashMap before JDK 8. I also understood the code: it was pretty modular and not very hard to understand. The code of ConcurrentHashMap in JDK 8 has changed a lot from its previous implementations. Because this…
0
votes
1 answer

How to detect thread is waiting for atomic reference

I have singleton which holds connection to external service, this connection is declared as atomic reference Connection connection = new AtomicReference<>(new Connection()); As long as this connection is used by my webservice, many threads may…
Kasper Ziemianek
  • 1,329
  • 8
  • 15
0
votes
0 answers

How to create concurrent sorted map based on value?

I need to create a concurrent map with parameters. The map should be sorted based on it's value, when I increment the AtomicLong, it should also balance itself. The problem with ConcurrentSkipListMap is that it cannot sort the…
0
votes
1 answer

ScheduledExecutorService scheduleWithFixedDelay for Callable

I am trying to execute a periodic action using Java Concurrency package and I am using the following code: ScheduledExecutorService daemon = Executors.newScheduledThreadPool(1); daemon.scheduleWithFixedDelay(new…
Dan Smith
  • 423
  • 2
  • 5
  • 17
0
votes
1 answer

Second thread doesn't start in producer consumer example

I'm trying to implement Producer and Consumer problem by using semaphores in java. The issue is when I start two threads (Producer and Consumer) consumer doesn't start and producer blocks itself after buffer is full. I mean it looks like there is…
quartaela
  • 2,579
  • 16
  • 63
  • 99
0
votes
2 answers

ArrayBlockingQueue: concurrent put and take

Why ABQ has not been implemented using the way LinkedBlockingQueue. We can use AtomicInteger to keep Track count in ABQ also the same way LBQ does. We can use the Two Locks for ABQ too. I stumble upon the similar question on SO. ArrayBlockingQueue…
0
votes
1 answer

Insertion of null value in a ConcurrentSkipListMap Java

I know it's maybe not the best thing to do and that I'm not using properly this object, but here is my problem. I want to use a ConcurrentSkipListMap and have declared my map as such: private ConcurrentSkipListMap map Sometimes, I need to…
BlackLabrador
  • 2,829
  • 5
  • 18
  • 21
0
votes
1 answer

How to kill a submitted Callable doing uninterrupible IO that won't return

I am trying to build a SIMPLE test case to send to IBM to try to resolve this issue I thought it would be simple to gin up a JUnit Test case or a little main app that made the calls and show that the MQ call never returned. I thought I'd use the…
Steve Cohen
  • 4,679
  • 9
  • 51
  • 89
0
votes
2 answers

for each in blocking collection

Suppose I have an instance of LinkedBlockingQueue queue; and want to use for each with this queue: for(Object obj : queue) { //do smth } How will this code behave in case if queue is empty at the moment? Will it block the running until queue…
0
votes
1 answer

Replace Await, Signal, SignalAll with wait,notify and notifyAll

I want to replace await(),signalAll() with wait(),notifyAll() (java's default monitor) and my code listed below, the problem is that once thread get into waiting state. it never be notified again.. Thanks for your help. import…
0
votes
1 answer

Java Executors.newFixedThreadPool() - Ideal Number of Threads in a Web App?

In a Java web application, I have a question about the ideal number of threads to create when using the newFixedThreadPool() The examples from Java Concurrency in Practice always recommended creating it with…