In: Computer Science
Basic steps involved in the creating Thread
Basically Thread is a light weight process, java language provides support for multi threading.
Thread contains several states
i)new: When we create a instance of Thread class new thread will be created
ii)Running: The java thread in a running state.
iii)Suspended: A running thread can be suspended when temporarily it's activity,once other thread stops it'll be activated by default.
iv) Blocked: When thread can be blocked waiting for a resource
v) Terminated : A thread can be terminated when it's execution is completed , once the the Thread terminated it can't be resumed.
CreateThread.java
class CreateThread extends Thread
{
public void run()
{
System.out.println("Thread is running);
}
public static void main(String args[])
{
CreateThread c=new CreateThread();
c.start();
}
}
2)
i)The reason why we disable the interrupts is it could lead to a dead lock , if an interrupt handler tries to acquire a lock that the interrupted thread has acquired
ii) To protect against the thread owning the lock getting preempted by a rescheduling interrupt and amount of time the lock remains held being extended to an unaccepted long time.
iii) Generally users aren't allowed to use that kind of instruction only it'll be by kernel process.users only access by some routine offered by Kernel API.If the program has some bug or for some reason needs some resource that will be only avliable when some interrupt arrives it enters on infinite loop and the entire CPU will be held by the process.
iv) After that system even can't be restarted only can be rebooted.