Top 100+ Advanced Multithreading Interview Questions 2019-2020 - 1

Question: 1

What are the difference between extending the Thread class and implementing the Runnable interface?

Extending the Thread class will make your class unable to extend other classes, because of the single inheritance feature in Java. However, this will give you a simpler code structures. If you implement runnable, you can gain better object oriented design and consistency and also avoid the single inheritance problems.

Question: 2

What invokes a thread’s run() method?

After a thread is started, via its start() method of the Thread class, the JVM invokes the thread’s run() method when the thread is initially executed.

Question: 3

What is the use of start() function in starting a thread?

The start() method tells the Java Virtual Machine that it needs to create a system specific thread. After creating the system resource, it passes the Runnable object to it to execute its run() method. Calling the run() method directly has the “Thread” execute in the same thread as the calling object, not in a separate thread of execution, as intended.

Question: 4

How does multi threading take place on a computer with a single CPU?

The operating system’s task scheduler allocates execution time to multiple tasks. By quickly between executing tasks, it creates the impression that tasks execute sequentially.

Question: 5

What object does non static synchronized methods use for locking?

Non static synchronized methods synchronize on the instance (this) of the class.

Related Questions