Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help.....Thread

 
Aru Ven
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
Can anyone explain me the output of the program.....

Thanks in advance.
Aruna
 
Vladimir Kositsky
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi!
both treads increment i,k, and j in each of eternal loop invocation and return equal values.
so letters printed if workWithoutLocks( ) executed between first and second variables increment , and it is possible without any legimitacy.
see example 9.6 Mugal and Pasmussen
cheers
 
shalini Rajan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Aruna,
I can't predict the result.Itz displaying infinite 'j' thatz right but some time it displays i & k also.I don't know why?.Lets wait for others to answer.
Shalini
 
Praveen Zala
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Aru,
The code that u have posted started printing k,j.........and so
on ...it prints the same witout stopping ...infinitely....
Wonder why it does that !
Prav
 
Nasir Khan
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I changed the line if (j1 != j2) System.out.println("j");
with if (j1 != j2) System.out.println(j1+"j"+j2);
and found that the condition j1 != j2 is true after going through several loops ..
It seems that after sometime one thread lags behind the other one
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic