• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Doubt on thread

 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The following is a question from JavaBeat mock exam.



The choices are given as:

1. The program will output 'Active Thread' pause for a while and then print 'Inactive
Thread'.
2. The program will output 'Inactive Thread' pause for a while and then print 'Active
Thread'.
3. The program will throw a run-time exception.
4. The order of the outputs will vary upon execution.

Correct answer is given as choice 1. But I thought, it was option 4, as the order of thread execution is entirely VM dependent.
 
author
Posts: 23959
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Correct answer is given as choice 1. But I thought, it was option 4, as the order of thread execution is entirely VM dependent.



Well, yeah... but... Are there any VMs that will starve a thread for 4 whole seconds? Especially, since there are no other running threads in the system?

For the other case to happen, the inactive thread has to start first, sleep for 4 seconds, and in that time, the VM does nothing. It may be VM dependent, but have you seen a VM that does that?

Generally, when we are talking about starting threads, timeslice periods, priority behaviors, these are in the realm of milliseconds.

Henry
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic