Skip to content
Advertisement

Tag: java.util.concurrent

Resubmit Callable to executorService on exception

My situation I’m trying to craft a functionality which would execute n (where n >=0) requests to a given endpoint, but I do understand that sometimes that endpoint might not respond due to 500 error or other issue, so I want to repeat my requests to an endpoint (with a small interval in between [not yet implemented]) till I get

Java concurrent programming – endless loop

I am reading the book Introducing Play Framework: Java Web Application Development (ISBN 978-1-4842-5645-9) and there is this example on Callable: My question is, if the computation of the Future throws and exception, will the while loop run forever? In my opinion, yes, it will loop forever. First, if the Future computation throws an exception, then future.isDone() always evaluates to

What does “Aren’t allocating the things put into queues” mean?

I’m reading this: https://concurrency.markmail.org/search/?q=ArrayBlockingQueue+LinkedBlockingQueue#query:ArrayBlockingQueue%20LinkedBlockingQueue%20from%3A%22Doug%20Lea%22+page:1+mid:sgx3amdfga7esqul+state:results In which Doug Lea says: Usually, when you are putting something into a queue, you will have just allocated that new something. And similarly, when you take something out you usually use it and then let it become garbage. In which case the extra allocation for a queue node is not going to make much difference

Why does calling CompletableFuture::cancel cause an immediate CancellationException

I am trying to call cancel on CompletableFuture. It seems from the docs: If not already completed, completes this CompletableFuture with a CancellationException. Dependent CompletableFutures that have not already completed will also complete exceptionally, with a CompletionException caused by this CancellationException. That it should complete them exceptionally which is what I was expecting but instead, it throws and immediate CancellationException.

CompletableFuture from Callable?

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 me very obvious and useful utility method) missing? Am I missing something? Answer You are supposed to use supplyAsync(Supplier<U>) In general, lambdas and checked exceptions do

future.cancel does not work

I have a nice and compact code, which does not work as I expected. The output is : Timeout true END Question: Why does not terminate the future.cancel(true) method the called Runnable? After the program wrote the “END” to the output, the “r” Runnable is still running. Answer The problem is that your Runnable is not interruptible: task interruption is

Usecase of using AtomicStampedReference & AtomicMarkableReference

I am looking for a example of AtomicStampedReference and/or AtomicMarkableReference, that could help me understand these classes and their functions. I am not able to get any quality examples over the web. I can think of using these in garbage collection, but a quality example will help me understand these better. Answer Practical examples (Complicated) For AtomicMarkableReference: https://github.com/arunmoezhi/ConcurrentKaryST For AtomicStampedReference

Advertisement