• 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
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Thread Question

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 thread's stop method.
4) A call to halt method of Thread Class.

According to me the correct answer are : 1,3.

Now in the above answer i m little confused for option 2. Becos as far as my knowledge are concern, it is not mendatory that a currently running thread will stop execution and go to runnable state when another thread of the higer priorty comes.

Am i right?
 
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think, that the Schedular is meant to ensure that all threads in the runnable pool have an equal or lower priorty then the current running thread. (not sure how much of a gurarantee you can place on that).

I would have picked 1 and 2, I dont think I would have picked 4 because there is no halt method, and until I just checked I wouldnt have picked 3 because I thought there was no stop method. However stop is depricated so it should not be used anyway.

Strange, threads was one of the chapters i did best at in the book, and it si the part of java I have avoided the most.

[ September 18, 2007: Message edited by: Gavin Tranter ]
[ September 18, 2007: Message edited by: Gavin Tranter ]
 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Fore sure the System.exit() will make all the threads stop, because it terminates the currently running JVM.

Now, a thread receiving higher priority will not make the thread stop. As matter of fact, depending on the computer architecture it may not even pause the execution to let the other thread run (i.e. the computer may have multiple processors). At any rate, pausing the execution of thread to let another thread with higher priority run is not interpreted as stoping the thread execution.

That being said, the Thread class does not have a halt() method, and although the stop() method is deprecated, it still works and would stop the thread execution.

Therefore, I daresay the correct answers should be: 1 and 3.

[ September 18, 2007: Message edited by: Edwin Dalorzo ]
[ September 18, 2007: Message edited by: Edwin Dalorzo ]
 
Gavin Tranter
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah the difference between stop and pause
most read these questions more carefully if I am to pass
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My OS knowledge says, there are two types of process-scheduler.
1. Preemptive (forceful - most of the OS have such)
2. Non-preemptive(rarely used)

Hence, theoritically, you can have a non-preemtive process-scheduler which lets the current thread run till its completion/error and then will allow any other treahd for its turn, regardless of its Pririty.

So, thread will Not stop under All circumstances if a high priority thread is available.
 
Looky! I'm being abducted by space aliens! Me and this tiny ad!
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic