Explain the method of Runnable interface with example?
Submitted by: AdministratorIn this method of creating thread, we have to implement the Runnable interface and implement the run() method in our class.
We have to create an object of our class.
Then we you have to pass the reference of that object for creating a new object of Thread
Invoke the start method using this Thread object which will create a new thread of execution.
For example
public class MyThread implements Runnable{
public void run(){
// code to execute under the thread
}
public static void main(String [] args){
MyThread c = new NewThread();
Thread t = new Thread(c);
t.start();
}
}
Submitted by: Administrator
We have to create an object of our class.
Then we you have to pass the reference of that object for creating a new object of Thread
Invoke the start method using this Thread object which will create a new thread of execution.
For example
public class MyThread implements Runnable{
public void run(){
// code to execute under the thread
}
public static void main(String [] args){
MyThread c = new NewThread();
Thread t = new Thread(c);
t.start();
}
}
Submitted by: Administrator
Read Online Java Multi-Threading Job Interview Questions And Answers
Top Java Multi-Threading Questions
☺ | Explain deadlock? |
☺ | What is the sleep() method Data type for the parameter? |
☺ | Explain the difference between preemptive scheduling and time slicing? |
☺ | How many threads at a time can access a monitor? |
☺ | Name the default thread at the time of starting the program? |
Top Java Programming Language Categories
☺ | Core Java Interview Questions. |
☺ | Hibernate Interview Questions. |
☺ | Advanced Java Interview Questions. |
☺ | IBM WebSphere Interview Questions. |
☺ | Spring Framework Interview Questions. |