Skip to content
Advertisement

Tag: multithreading

Why can’t server and client be started together?

Relevant code: Why can’t the server and client be started together in the @Test? I think it gets stuck in the infinite while loop but at the same time, shouldn’t there be context switching with the new threads started after accepting the connection? I expected at least the name of the 2 new threads to be printed but it doesn’t

Java Thread is blocked in join()

I have the following simple code in which I put and take from a Queue represented as an ArrayList. I don’t understand why my thread is blocked in join() method. From main I call as follow: Answer Without running it… The close() method holds lock at the time it calls thread.join() and waits on thread (forever) thread is waiting 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

Correct way to decrement an AtomicLong by a certain delta

Given an AtomicLong object, what is the right way to decrement the value by a delta? Option 1 Option 2 While both give the desired result, I want to understand under what circumstance will they not represent the desired behavior i.e to decrement a long value atomically? (One drawback of the second approach for example could be the negative sign

service.shutdownNow() not killing the thread

In my application im spawning a single thread executor and in the thread I’m doing logic of loading ML models/predictions. If any of the logic exceeds the time-limit(4 minutes), I’m shutting down the thread. But when the application is up, when time out happens, I’m able to see logs of threads getting shut down. But the process(Prediciton logic) continues to

How does a thread work with Handler in Android?

In the code section given below, I have run a thread on a button click. At first, the thread will set text to the textView, then it will sleep for 6 seconds. But, in reality on the button click, at first, the thread is sleeping for 6 seconds and then it is setting text to the textView. Now, why is

Advertisement