wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Threads" Watch "Threads" New topic
Author

Threads

Savio Mascarenhas
Ranch Hand

Joined: Nov 29, 2000
Posts: 108
Q3.[Check all correct answers]
You have an application which executes the following line:
Thread myT = new Thread();
myT.start();
Select all the following statements that are correct.
(a)The Thread myT is now in a runnable state.
(b)The Thread myT has NORM_PRIORITY priority.
(c)The Thread will die without accomplishing anything.
(d)The run() in the class where the statement occurs will be executed .
The answers mentioned were (a) & (c).Should (c) or (d) be selected . Should'nt (b) be included since,if not explicitly set a new thread has Normal priority.
Deepak Magoo
Greenhorn

Joined: Nov 27, 2000
Posts: 22
Hi Savio
I think that the answers should be a,b,d. a is correct coz when u create an instance of thread it is in runnable state. anwer b is correct coz the default priority as u say for a thread is NORM_PRIORITY. i do not understand the third option. the last option should be correct because the start() is going to call the run(). tell me if i am correct or wrong.
Deepak
Sahir Shah
Ranch Hand

Joined: Nov 05, 2000
Posts: 158


The thread will have the same priority as the parent thread.


....
naveen sahu
Ranch Hand

Joined: Nov 15, 2000
Posts: 48
Originally posted by Savio Mascarenhas:
Should'nt (b) be included since,if not explicitly set a new thread has Normal priority.

no , b can't be 100% true always.
because if not explicitly mentioned a thread always have priority equal to that of creating thread. and creating thread may have a priority b/n 1 to 10.
Aru Ven
Ranch Hand

Joined: Sep 28, 2000
Posts: 199
Hi All,
Select all the following statements that are correct.

(a)The Thread myT is now in a runnable state.
(b)The Thread myT has NORM_PRIORITY priority.
(c)The Thread will die without accomplishing anything.
(d)The run() in the class where the statement occurs will be executed .

I think (A) is the only correct answer.
start method will make the thread runnable.... it is upto the JVM/OS to decide when the thread will run.(which explains (d) is False, bcoz start method does'nt call the run).
The newly created thread will always have the priority of its parent thread. so (B) is false.
Regarding (c).... It think it is False... but I still doubt....
can anyone throw some light on it....

Thanks
Aruna
[This message has been edited by Aru Ven (edited December 07, 2000).]
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi All,
(a) True. Invoking start() places the thread in the Runnable state.
(b) False. Threads inherit their priority from the thread that starts them which may or may not be NORMAL_PRIORITY.
(c) True. They haven't given any code to implement run().
(d) False. Invoking start() allocates system resources, schedules the thread, and calls run() BUT when it actually executes depends on the Scheduler (See Sun Java Thread tutorial).
Hope that helps.
------------------
Jane
The cure for boredom is curiosity.
There is no cure for curiosity.
-- Dorothy Parker


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
mohit joshi
Ranch Hand

Joined: Sep 23, 2000
Posts: 243
just for clarity, the code given has constructed a thread object without passing any runnable, ( and has also not made object of a subclass of Thread to provide implementation of run). So the default run method doesnot do anything.
Doesnt thread priority vary from 0 to 10, that is 11 different levels of it?? I remember reading this somewhere.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
C is correct because the the constructor of the Thread takes a Runnable object. Since none was passed, we are starting a default Thread which does nothing. In order for the run() method of the included class to be invoked, we must instantiate the Thread with:
Thread myThread = new Thread(this);


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
ming fan
Greenhorn

Joined: Nov 15, 2000
Posts: 21
Originally posted by mohit joshi:
just for clarity, the code given has constructed a thread object without passing any runnable, ( and has also not made object of a subclass of Thread to provide implementation of run). So the default run method doesnot do anything.
Doesnt thread priority vary from 0 to 10, that is 11 different levels of it?? I remember reading this somewhere.

Priority ranges from 1 to 10, so only 10 levels.
mohit joshi
Ranch Hand

Joined: Sep 23, 2000
Posts: 243
Another Clarification:
From Java Threads by Scott Oaks and Henry Wong : page 138
"Every thread has a priority value that lies somewhere in the range between MIN_PRIORITY(which is 1) and MAX_PRIORITY( which is 10).....
...In addition, the virtual machine is allowed to create internal threads at a priority of 0, so that there are in effect 11 different priority levels for threads within the virtual machine."
From the above it looks like java programmers can create threads with priority 1 to 10, and cannot create threads with priority 0.
[This message has been edited by mohit joshi (edited December 09, 2000).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Threads
 
Similar Threads
Thread question?
ExamCram - Threads
Thread Question
EXAMCRAM CD Q:TEST 2, Q 11
exam cram