Vidyalelo
Java Programming · Q64

Threads

Programming · Java Programming · question 64

Q64

Which of this method can be used to make the main thread to be executed last among all the threads?

A.
stop()
B.
sleep()
C.
join()
Answer
D.
call()

Answer: Option C

Solution

Answer: Option C
Solution:
The join() method in Java is used to pause the execution of the current thread until the thread on which join() is called has finished executing.

To ensure that the main thread executes last, we can call the join() method on all other threads in the main thread.

This causes the main thread to wait for the completion of other threads before it proceeds.

sleep() is used to pause a thread for a specific time, not to coordinate the order of thread completion.

stop() is deprecated and unsafe.

call() is not a valid method for controlling thread execution in this context.