Win a copy of Learning Regular Expressions this week in the General Computing forum!
  • 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

threads question in examLab practice test 1  RSS feed

 
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am really sorry as i am posting such lengthy problems but please help me to understand this code
I know you will have to write lots of explanation but please help me
it is not the case that I have not tried but I am not able to understand
and the ExamLab explanation was not enough for me

here is the code


The anser is code compiles but no output and program does not terminate
 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Prasad Kharkar wrote:I am really sorry as i am posting such lengthy problems but please help me to understand this code
I know you will have to write lots of explanation but please help me
it is not the case that I have not tried but I am not able to understand
and the ExamLab explanation was not enough for me



Hi,

I don't blame you for the question. Don't be apologetic. I assume most people taking ExamLab are in the same boat. These questions are really tough to crack. IMO this particular code is not trivial and it needs a lot of analysis and insight to be able to understand and answer. If I have the time and patience to do the analysis, I shall post my findings. Otherwise I am sure there are experts out here who will help!

Good luck
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Prasad,

In this program you have two threads , main thread and b. After starting b thread , main goes to sleep.
Now b thread get chance to execute . It calls run method and doTask2() method , where it acquires lock of object a
and joins main thread . Due to this, thread b goes in block state with lock of object a .
Now when main thread come out of sleep state . It try to call doTask1() method on object a , but because this method is synchronized , it needs lock of object a , but lock is not available, because it is with thread b.

So both threads now in block state.


Hope it will help you
 
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

dipayan chatterjee wrote:Hi Prasad,

In this program you have two threads , main thread and b. After starting b thread , main goes to sleep.
Now b thread get chance to execute . It calls run method and doTask2() method , where it acquires lock of object a
and joins main thread . Due to this, thread b goes in block state with lock of object a .
Now when main thread come out of sleep state . It try to call doTask1() method on object a , but because this method is synchronized , it needs lock of object a , but lock is not available, because it is with thread b.

So both threads now in block state.


Hope it will help you



Great, Exactly.
Try this code :
 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
very well replied dipayan
nice work
thanks for that
thread resolved
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!