Java Threading Interview Questions and Answers for Experienced - 1
What is semaphore?
Semaphore is an object which helps two threads to communicate with one another in order to synchronize there operation.
What are daemon threads?
Daemon threads are designed run in the background. One example of a daemon thread is the garbage collector thread. You can use setDaemon () to mark a thread as daemon.
What is the difference between thread and process?
A thread is a path of execution that run on CPU, a process is a collection of threads that share the same virtual memory. A process has at least one thread of execution and a thread always run in a process context.
A process is a collection of virtual memory space, code, data and system resources.
A thread is code that is to be serially executed within a process.
A processor executes threads, not processes.
One more significant difference between process and thread is every process has its own data memory location but all related threads can share same data memory and have their own individual stacks. Thread is a light weighted process, collection of threads become process.
How do we create threads?
There are two ways to create a thread.
extend the java.lang.Thread clas:
Create a class which extends the thread class. When the class is instantiated, the thread and object are created together and the object is automatically bound to the thread. By calling the object’s start() method, the thread is started and immediately calls the object’s run() method.
Implement the java.lang.Runnable interface:
Create a thread and supply it an object with a run() method. This object will be permanently associated with the thread. The object’s run method will be invoked when the thread is started. This method of thread creation is useful if you want many threads sharing an object.
What is thread safety and synchronization?
Thread safe is used to describe that can run safely in multithreaded environments allowing accessing to data in a safe and efficient way.
Thread safety is achieved by synchronization .
Synchronization assures that the object data is not accessed by multiple threads at the same time.
100+ Statement and Courses of Action Practice Questions Pdf More
100+ Statement and Course of Action Questions for SBI PO More
100+ Statement and Courses of Action Questions and Answers More
1001+ Puzzle Questions and Answers Pdf Download More
Top 1000+ Logic Maths IQ Test Questions and Answers More
1000+ General English Questions & Answers for SBI Clerk Exam More
500+ Parajumbles Questions with Answers Pdf for IBPS PO, SO, Clerk More
High School Chemistry Questions and Answers More
100+ Vocabulary Words with Meaning and Sentence Pdf More
Verbal Reasoning MCQs with Answers More