What is the use of RUNNABLE interface in java?
What is the use of RUNNABLE interface in java?
Runnable interface is a type of functional interface which is designed to provide a common protocol for objects that wish to execute code while they are active.
It help to provide the information to read & execute the programming code. http://www.cashforcarsbroward.com/
Mari-Marketing.com | Notjustwebsite.com | Feebam.com | Carolinarugandupholstery.com | Jaffermerchantcpa.com | Usedfitnesssales.com | Gofaithstrong.com | SheltonRoofingCompany.com | LilacAssistant.com | Brilliantglass.net | Hopcconfire.com | Smpaving.com | Intelligentofficesuite.com | ABCAutoShipping.com | VisitMiamiTours.com
When you implement Runnable, you can save a space for your class to extend any other class in future or now. When you extends Thread class, each of your thread creates unique object and associate with it. When you implements Runnable, it shares the same object to multiple threads.
- java.lang.Runnable is an interface that is to be implemented by a class whose instances are intended to be executed by a thread. There are two ways to start a new Thread – Subclass Thread and implement Runnable. There is no need of subclassing Thread when a task can be done by overriding only run() method of Runnable.
Thus,Runnable interface is a type of functional interface which is designed to provide a common protocol for objects that wish to execute code while they are active.
- The Runnable interface should be implemented by any class whose instances are intended to be executed by a thread. The class must define a method run. It is used to create thread.
- public void run(): is used to perform action for a thread.
The runnable interface is a type of functional interface designed to provide a common protocol for objects that want to execute code when they are active. The Runnable interface must be implemented by every class whose instances are intended to be executed by the thread. The class must define the method that is run.
|
Bookmarks