Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

THREADS :PLEASE HELP

 
Raj Mehra
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dear friends,
Can anyone explain to me why the following program, doesnot show any output.
Thnx in advance.
 
khudiram Barik
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This may be possible.
Since the doIT() is not synchronized both the thread can access the method concurrently. When the first one finishes the 1st synchronized block and goes for the statemnt j1++, the second one can enter into 1st synchronized block and so on, we can never predict the locks. Since the variables are volatile concurrent changes will effect both the threads and hence you may not have the System.out.println statements get executed.
Thanks.
khudi
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic