• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Thread scheduling question(Marcus Green's NO2)

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Again I encountered this problem.
Again I got it wrong.
Question 22)
What can cause a thread to stop executing?
1) The program exits via a call to System.exit(0);
2) Another thread is given a higher priority
3) A call to the thread's stop method.
4) A call to the halt method of the Thread class
I always think 2) is incorrect but everytime I am wrong.
I think in time-slicing system,even when a thread with higher priority gets runnable,the thread scheduler won't let it to run until the original running thread finishes its time-slice.
Please help me with this.I am appearing the test in 3 days.
If I encounter this question again in real test,should I choose it or not?
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bin,
low or normal priority threads are nothing but us driving on the street. If emergency vehical wants to travel on the same street at the same time then we have to yield.
Hope this will help.
 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the question has to be concerned with what is GUARANTEED behaviour by the JVM. How threads with differing priorities behave is left upto the OS. An applet with threads of differing priorities run (for example) on a Netscape browser and on MSIE will behave differently - and (I hope) you won't get a question whose answer is so platform-dependent.

 
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think even threads with higher priorities will not be guaranteed to run. Sometimes, JVM will choose threads of lower priorities over higher priorities to avoid starvation. I hope the exam will not ask a badly made question like this.
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bin,
The question is "What can cause a thread to stop executing?". Java is implemented on systems that use either pre-emptive scheduling, time-slicing or a combination of both. On some systems a higher-priority thread can preempt a running thread with lower priority.
From other comments I've seen by people taking the real exam you need to watch out for questions wording. In this can cause implies you must take all possible situations into account.
Hope that helps. Best of luck on the exam.
------------------
Jane
The cure for boredom is curiosity.
There is no cure for curiosity.
-- Dorothy Parker
 
I'd appreciate it if you pronounced my name correctly. Pinhead, with a silent "H". Petite ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic