Вы находитесь на странице: 1из 10

Multithreading

Interview Questions

WWW.JAVA2BLOG.COM
Que: What is Multithreading?
Multithreading is a process of executing
multiple threads simultaneously.

Que: Is it possible to start thread


twice?
No, we can't start a thread twice. If we try to
do this then the exception is thrown.

www.java2blog.com
Que: What are advantages of
thread over the process?
Thread is a separate path of execution.

Threads are light weight process

Threads share same memory area.

The cost of communication between


threads is low.

www.java2blog.com
Que: How we create a thread in
Java?
In Java we can create a thread using two ways:

By implementing Runnable interface.

By extending Thread class

www.java2blog.com
Que2: Differences between sleep()
and wait() ?

sleep() is a method of Thread class while


wait() is a method of Object class.

sleep() method doesn't release the lock


while wait() releases the lock.

www.java2blog.com
Que: what you understand about
Thread Priority?
We can assign priority to threads so that the
highest priority thread will execute first then low
priority thread will get executed but it mostly
depends on thread scheduling algorithms. we can
assign priority to threads from 1 to 10. 1 is a low
priority, and 10 is a high priority.

www.java2blog.com
Que: Difference between the User
thread and Daemon thread?
If we create threads in Java, these threads are
called User threads. Daemon threads are low
priority threads that are used to provide
services to user thread. Daemon threads run
into the background.

www.java2blog.com
Que: How can we pause the
execution of the thread
for a particular time?
We can call sleep() to pause execution of the
thread for a specific time. When we call sleep
method for a thread it will switch to the waiting
state for a specific time and after time interval
expires thread moves to runnable state.

www.java2blog.com
Que: what is synchronization?

Synchronization is a process of controlling the


access of multiple threads to any shared
resource. it is mainly used to prevent
interference between threads. It also solves
consistency problem.

www.java2blog.com
thank you

WWW.JAVA2BLOG.COM

Вам также может понравиться