Forums Register Login
Is the following program thread safe ?. Please help...
I've been trying to analyze the following class and see that there is always a dead lock in the following call to hello.

Yep this is a multithreaded application.

Have you thought about synchronizing the "hello" method ??
Well, to be sure, create a thread dump. If it's on Windows you press Ctrl + Break. For example, if we have an obvious deadlock like this:

Then pressing Ctrl + Break on Windows gives you a bunch of text that highlights the deadlock like this:

... a lot of text ...

Found one Java-level deadlock:
waiting to lock monitor 0x02a807cc (object 0x2405edb0, a java.lang.Object),
which is held by "Thread-0"
waiting to lock monitor 0x02a82094 (object 0x2405edb8, a java.lang.Object),
which is held by "Thread-1"

... a lot more text ...

If you name your threads properly, you can see that this info can be very useful.
The human mind is a dangerous plaything. This tiny ad is pretty safe:
ScroogeXHTML 7.1 - RTF to HTML5 / XHTML converter

This thread has been viewed 653 times.

All times above are in ranch (not your local) time.
The current ranch time is
Feb 21, 2018 07:35:40.