my dog learned polymorphism*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubts in thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubts in thread" Watch "Doubts in thread" New topic
Author

Doubts in thread

Lavanya Raguram
Greenhorn

Joined: Apr 03, 2006
Posts: 27
1) how many locks does an object have?

a) one
b) one for each synchronised method.

2)Threads are guaranteed to run with the same priority that u set using set Priority() method

a)True
b)False

3)Is it possible to write a code that executes only if the current thread owns multiple locks?

a)True
b)False

4)Which of the following are true?

a)when an applicaton begins running there is one daemon thread whose job is to execute main
b)when an applicaton begins running there is one non - daemon thread whose job is to execute main
c)A thread created by daemon thread is initially also a daemon thread
d)A thread created by non daemon thread is initially also a non daemon thread

pls explain the relevant answers
Edisandro Bessa
Ranch Hand

Joined: Jan 19, 2006
Posts: 584
Hi Lavanya,


1) how many locks does an object have?
a) one
b) one for each synchronised method.


Option A is correct.

A given instance of an object can have only one lock belonging to a given thread. If another thread needs to own the lock on that given instance, the previous thread have to release it first.


2)Threads are guaranteed to run with the same priority that u set using set Priority() method

a)True
b)False


Option B is correct.

Normally, priorities are integer values between 1 and 10. However, the values from 1 through 10 are not guaranteed because some JVMs might not not recognize ten distinct values. In this case, such JVMs can use priorities between 1 to 5.


3)Is it possible to write a code that executes only if the current thread owns multiple locks?

a)True
b)False


Option A is correct.

It's totally legal to use nested synchronized code in your program in order to own the lock on multiple objects.

For example, supposing that obj1 and obj2 are distinct references to different class types :


4)Which of the following are true?

a)when an applicaton begins running there is one daemon thread whose job is to execute main

b)when an applicaton begins running there is one non - daemon thread whose job is to execute main

c)A thread created by daemon thread is initially also a daemon thread

d)A thread created by non daemon thread is initially also a non daemon thread


First of all, keep in mind that daemon threads are not on SCJP5 exam. Simply don't worry about daemon threads.

The correct answers are B, C and D.

Explanation for B: Initially the JVM starts a single non-daemon thread which typically calls the method main of some class.

After that the JVM may also create other daemon threads for internal purposes such as Garbage collection for example.

Explanation for C and D : When a new thread is created, that new thread will be marked as a daemon thread by default only if the creating thread is also a daemon thread.

It doesn't mean that non-daemon have always to be a non-daemon thread. You can define whether or not a given thread is a daemon thread by calling setDaemon method in class Thread.

For more detailed explanations about daemon threads please check it out :

http://java.sun.com/docs/books/vmspec/2nd-edition/html/Concepts.doc.html#33308


"If someone asks you to do something you don't know how to, don't tell I don't know, tell I can learn instead." - Myself
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubts in thread
 
Similar Threads
JQuest Cert Simulation Question
Thred Should run even after Program terminates
Daemon Thread
Daemon Thread
synchronized