Core java interview questions on Thread



1.What is multithreading?
Multithreading is a process of executing multiple threads simultaneously. Its main advantage is:
Threads share the same address space.
Thread is lightweight.
Cost of communication between process is low.

2.What is thread?
A thread is a lightweight subprocess.It is a separate path of execution.It is called separate path of execution because each thread runs in a separate stack frame.

3.What is the difference b/w preemptive scheduling and time slicing?
Under preemptive scheduling, the highest priority task executes until it enters the waiting or dead states or a higher priority task comes into existence. Under time slicing, a task executes for a predefined slice of time and then reenters the pool of ready tasks. The scheduler then determines which task should execute next, based on priority and other factors.

4.What does join() method?
The join() method waits for a thread to die. In other words, it causes the currently running threads to stop executing until the thread it joins with completes its task.

5.What is difference b/w wait() and sleep() method?

6.Is it possible to start a thread twice?
No, there is no possibility to start a thread twice. If we does, it throws an exception.

7.can we call the run() method instead of start()?
yes, but it will not work as a thread rather it will work as a normal object so there will not be context-switching between the threads.

8.What about daemon threads?
The daemon threads are basically the low priority threads that provides the background support to the user threads. It provides services to the user threads.

9.Can we make the user thread as daemon thread if thread is started?
No, if you do so, it will throw IllegalThreadStateException

10.When Should we interrupt a thread?
We should interrupt a thread if we want to break out the sleep or wait state of a thread.

11.What is Garbage Collection?

12.What is gc()?

13.What is the purpose of finalize()method?

14.Can an unreferenced objects be referenced again?

15.What kind of thread is garbage collector thread?

16.What is the difference between final,finally and finalize?

17.What is the purpose of runtime class?

18.How will you invoke external process in java?



Related Post

Comments

LanceCar
          ! : http://okaybro.ru : "Living For Love" http://okaybro.ru/foto-prikoly-interesnoe/2964-novoe-video-madonny-living-for-love.html http://okaybro.ru/foto-prikoly-interesnoe/2107-udivitelnye-ugolki-prirody-kotorye-svetyatsya-nochyu.html

©candidjava.com