Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Is the following program thread safe ?. Please help...  RSS feed

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you thought about synchronizing the "hello" method ??
 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
=============================
"Thread-1":
waiting to lock monitor 0x02a807cc (object 0x2405edb0, a java.lang.Object),
which is held by "Thread-0"
"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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!