Skip to content
Advertisement

Tag: concurrency

How to fix the Issue with replacing AsyncTask to connect socket?

I’m trying to use This approach(Marked Answer) to replace my code with AsyncTask to make connection between user in android and server, And here’s what I’ve done : Note: I’m not using any specific pattern, just trying to achieve this goal on a basic structure. MainActivity : ClientConnection : ConnectionTask : ConnectionRunningTask: So base on the above code I’ll try

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.

Is this the correct way to extract counts from a Concurrent Hash Map without missing some or double counting?

Working on something where I’m trying to count the number of times something is happening. Instead of spamming the database with millions of calls, I’m trying to sum the updates in-memory and then dumping the results into the database once per second (so like turning 10 +1s into a single +10) I’ve noticed some strange inconsistency with the counts (like

Why is volatile keyword not needed for inter-thread visibility when one of the threads involved is the main() thread?

Consider the following program: Here the stopRequested is not declared as volatile – so ideally the thread backgroupdThread must not stop – and execute endlessly But when running this locally – the thread backgroundThread is gracefully shutting down with the message: “Stopping the thread!!”. Are all the updates by the main() thread to the shared variable stopRequested visible to the

Advertisement