• 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

Thread Question

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is one of the 'Thread' questions from Java Certification Book by Khalid:
****************
Given the following program, which statement is true?

Choices:
1. The program will fail to compile.
2. One cannot be certain whether any of the letters i,j,k will be printed during execution.
3. One can be certain whether any of the letters i,j,k will ever be printed.
4. One can be certain that the letters i and k will never be printed during execution.
5. One can be certain that the letter k will never be printed during execution.
Correct Answer is: 2
*********
Can someone explain more clearly? The explanation given in the book is not very sufficient.
Thanks,
Gopesh
[ November 23, 2003: Message edited by: Gopesh Sharma ]
[ Jess added UBB [code] tags to preserve whitespace, check 'em out! ]
[ November 23, 2003: Message edited by: Jessica Sant ]
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the reason why 2 is correct is because of thread deadlock. The threads that are started are only made "ready" when MyThread.start()is called. The thread scheduler will then pick up these two threads (in no particular order) and start executing them. Once a thread has started executing it obtains a lock on the first synchronized statement and proceeds to execute it. The lock is released when the the thread proceeds to the next statement. It is possible for the JVM's thread scheduler to start executing the other thread at some stage during or after the first thread begins execution, however it is possible that a lock may be held on any of the synchronized statements by one of the threads - causing a possible thread deadlock, and hence the check method may never execute.
Hope this Helps
Phillip
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Check this Link. Threads
Regards,
Hari.
 
This cake looks terrible, but it tastes great! Now take a bite out of this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic