In case of preemptive scheduling the highest priority task executes until it enters the waiting or dead states or a higher priority task comes into existence.
Time slicing: In case of time slicing a task executes for a predefined slice of time and then re-enters the pool of ready tasks. The scheduler then determines which task should execute next, based on priority and other factors.
Note: if run() method is called directly without calling start() method than program will execute without any error but objects are treated as normal objects not thread objects.
Java interview questions on multithreading
- What is multithreading?
- Difference between process and thread in java?
- What is thread in java?
- What is the difference between preemptive scheduling and time slicing?
- What is join method in java?
- What is the difference between sleep and yield method?
- Is it possible to start a thread twice in java?
- Can we call run method directly in java?
- What is daemon threads in java?
- Can we make the user thread as daemon thread if thread is started?
- What is synchronization?
- What is synchronized block in java?
- What is synchronized method in java?
- What is static synchronization in java?
- What is deadlock in java?
- What is starvation in java?