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

Thread Prog...

 
Thangaraj Selvamani
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Options Are:
1.It prints 0.
2.It prints 999999.
3.The output is not guaranteed to be any of the above.

In Both The Codes Option 2 is correct...why option 3 is not correct

Source:
http://nikojava.wordpress.com/2008/09/08/scjp-mock-exam-for-threads/


[ November 01, 2008: Message edited by: Thangaraj Raj ]

[ November 01, 2008: Message edited by: Thangaraj Raj ]

[ November 01, 2008: Message edited by: Thangaraj Raj ]
[ November 01, 2008: Message edited by: Thangaraj Raj ]
 
Ankit Garg
Sheriff
Posts: 9528
32
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thangraj please Quote your source
 
Thangaraj Selvamani
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok...Ankit Garg...i have edited the source...
please check it...
 
Ninad Kulkarni
Ranch Hand
Posts: 802
Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Thangaraj Raj

In both cases main thread executes wait() on thread object after notify by thread object in case 1 main prints vlue of number
in second case answer is here

http://www.coderanch.com/t/270321/java-programmer-SCJP/certification/Threads

Regards
Ninad
 
Thangaraj Selvamani
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you...Ninad Kulkarni...my doubt is cleared...

but before " synchronized (thread) { "
this line gets execute...new thread is moved from runnable to running state...that time the main thread will be in blocked state for ever...if this happens how the 2nd option is possible...
[ November 01, 2008: Message edited by: Thangaraj Raj ]
 
long meng
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh yes, in case 1,if the Job(thread) run first,and after it complete,after that the main thread run,so will the main thread wait forever?
 
Tuna Töre
Ranch Hand
Posts: 220
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
main thread waits forever...
 
long meng
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so Anut Walidera ,if the main thread waits forever,then the main thread won't print anything out,so the answer should be "3.The output is not guaranteed to be any of the above."
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic