• 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: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question: [Check all the correct answers]
You have an application which execute the following line:
Thread myT = new Tread();
myT.start();

Select all of the crrect statements.
a. The Tread myT is now in a runnable state.
b. The Tread myT has the NORM_PRIORITY priority.
c. The Tread myT will die without accomplishing anthing.
d. The run method in the class where the statement occurs will be executed.
The answers are a and b. But why not b and d?
 
Daniel Liu
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, there was a typo in my original post so I it repost below.
You have an application which execute the following line:
Thread myT = new Tread();
myT.start();

Select all of the crrect statements.
a. The Tread myT is now in a runnable state.
b. The Tread myT has the NORM_PRIORITY priority.
c. The Tread myT will die without accomplishing anthing.
d. The run method in the class where the statement occurs will be executed.
The answers are a and c. But why not b and d? [/B]
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Daniel,
What you are doing is creating an instance of the Thread class, not of any of its' subclasses. Remember the run() method defined in the Thread class doesn't do anything? That's why the thread that you starts dies without accomplishing anything.
Usually we extend the Thread class or implement Runnable to provide our own implementation of the run() method. Then we create a thread from our class. But this question is perfectly valid and attempts to validate your knowledge about threads.
Beware of such questions in the exam!!
Ajith
 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ajith,
So which answers are the right ones for the question. Can you be a little more specific.
Thanks
Aruna
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What I think choice b is crrect too because the default priority value is NORM_PRIORITY
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the correct answers are (a) and (c).
Daniel, I don't think the answer (b) is right. When a thread is created, it "inherits" the priority of the parent thread. Eventhough the default priority is NORM_PRIORITY, we cannot assume anything about the thread which executes the given code.
Ajith
reply
    Bookmark Topic Watch Topic
  • New Topic