• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

threads question in examLab practice test 1

 
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
very well replied dipayan
nice work
thanks for that
thread resolved
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic