Relative Content

Tag Archive for javamultithreading

Understanding Thread Dump

I have Spring Boot 3 application which recently stops being responsive after few hours of uptime, I took a thread dump and all of ForkJoinPool.commonPool-worker stack trace look like this

Managing multiple exclusive locks for a set of unique values

Consider I have a number of string values (dynamically generated), and a thread pool, and I want each string value to be exclusively owned by at most a single thread at any time. So, for instance, if the string “foo” is locked by a thread T1 at some period in time, all other threads waiting to process “foo” (or any other string equal to “foo” in terms of Object.equals()) must wait until thread T1 releases the lock.

How to implement ThreadLocal?

I want to have a ThreadLocal of an implementor of AutoCloseable. I can’t find some kind of hook where I can ensure close() is called when the thread dies.

Main thread or sub thread responsibility

when a class extends thread class, having methods other than run() then which thread is responsible to execute the methods whether main thread or sub thread created for that class?

Execute an instance of Thread in an ExecutorService

I know we can execute Runnables in an ExecutorService which will be executed as separate threads. But I recently came across a situation where I need to know the state of a Thread during its executions. For that I created instances of Threads (instead of Runnable) and submitted it to an ExecutorService. However, the Thread state remained in NEW state. Syntactically the program had no errors but I feel I am missing something. Here is the sample program: