Rajiv Chelsea wrote:...why is it necessary?
It is necessary because the OS can switch contexts, temporarily pausing execution of the current thread from running in favor of allowing a different one run. At a later time the Thread will be re-started and needs to know precisely where it was when it was stopped because of the Context Switch.
Rajiv Chelsea wrote:How is it done...?
That is an implementation detail of the particular JVM you are running, and is not really necessary to know the details of - especially since it could be different between OSes, versions, or vendors. Why do you think you need to know how?