- Thread is execution instance which have its own execution environent(system resource).
- Thread is a unit of procees and it is a light weight.
- Thread class is define in java.lang package
- Jvm can run only runnable type object.
- Runnable is a interface available in java.lang package.
- Runnable have only one abstract method run()
- Thread class implement runnable interface where run method does not have any implementation
- Thread implementation started by calling start() method on thread type object.
2. By implementing runnable interface and
provide implementation to run()
Commonly used constructors of thread class:
- Thread(string name)
- Thread(runnable r)
- Thread(runnable r,string name)
Each thread in jvm has following properties.
Thread class provide gettter and setter method to access the properties like
- Start the thread execution in seperate stack and calls the run method of thread object
- You can not run thread twice.
2.public void run()
- Start the execution of task define in run() current execution stack.(no concurrency)