Multi-threading Flashcards
What is the difference between Process and Thread?
A process is an independent program execution unit with its own memory space, while a thread is a smaller execution unit within a process that shares the process’s memory.
What are the benefits of multi-threaded programming?
Benefits include better CPU utilization, improved application responsiveness, and the ability to perform multiple tasks concurrently.
What is difference between user Thread and daemon Thread?
User threads keep the application alive, while daemon threads are background threads that do not prevent the JVM from exiting when no user threads are running.
How can we create a Thread in Java?
A thread can be created by extending Thread or implementing Runnable and then invoking the start() method.
What are different states in lifecycle of Thread?
The thread lifecycle includes states like New, Runnable, Blocked,
Can we call run() method of a Thread class?
Yes, but calling run() directly won’t create a new thread; it will execute on the current thread.
How can we pause the execution of a Thread for specific time?
You can pause a thread using Thread.sleep(milliseconds).
What do you understand about Thread Priority?
Thread priority, between 1 and 10, influences the scheduling of threads but doesn’t guarantee the execution order.