Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Whiz Lab Question On THreads

 
Mohit G Gupta
Ranch Hand
Posts: 634
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whiz lab Quesiton



output:
abc

i have some doubt's

1.is the output 123 possible
2.can it's output be predicted
3.
Does it mean anything?
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mohitkumar gupta wrote:

1.is the output 123 possible

No. Did you check the JLS? With the sleep method, the thread who already acquired the lock, doesn't loose it!
mohitkumar gupta wrote:
2.can it's output be predicted

Yes, in this case!
mohitkumar gupta wrote:
3.
Does it mean anything?


The main thread get the lock of the object o.

And, for a exercise, change the sleep() method to wait() method on the object!

 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BTW, here is the JLS
 
Mohit G Gupta
Ranch Hand
Posts: 634
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1.
Why can't thread t1 start ??
2.
why do thread t1 require lock on o to run ??
3.
thread t1 start inside the synchronized block,why would it require lock ???
4.
how is main thread acquiring lock on o and not t1 ???



 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mohitkumar gupta wrote:1.
Why can't thread t1 start ??
2.
why do thread t1 require lock on o to run ??
3.
thread t1 start inside the synchronized block,why would it require lock ???
4.
how is main thread acquiring lock on o and not t1 ???


Dude, go through the Threads chapter once again. This is my advise!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic