Thread represent ability provided by Java to make Taft application, because thread in program have duty and function separate. With existence of thread, can make more efficient program in
There is two way of which can be used in making a thread, that is :
- Making subclass of thread
To run thread, can be conducted by calling method start(). moment of Start() run, hence in fact run method() of class will be run. Become to make thread, have to define run method() at definition of class.
- implementation of Interface Runnable
Way of this represent the way of simplest in making thread. Runnable represent abstraction unit, that is class which is implementation this interface only enough function implementation of run(). In function implementation of run(), we will define instruction which developing a thread.
- Daemon And of User Thread
There is two Kinds of thread in Java, that is and daemon of user thread. Daemon thread represent thread which is its life cycle depend on especial thread or mains, so that if mains thread end, hence automatically daemon thread-thread also follow to end. While thread user measure up to differ, where if especial thread have, hence thread user will continue to be run.
- Sleep
Arranging thread to discontinue its process a moment and give opportunity at other process or thread.
- Interrupt
If wishing an thread to discontinue process, hence require to call interrupt method. Interrupt used to give signal at thread to discontinue its process.
- Synchronized
Synchronization is block or method owning addition of keyword synchronized, so that if run hence only one thread at one time which can run program block or method. Other Thread will await thread which is executing this method till finish. Synchronization mechanism important in the event of division of data and also resource among thread-thread. Synchronization also lock at data or resource which is processing.
Thread represent ability provided by Java to make Taft application, because thread in program have duty and function separate. With existence of thread, can make more efficient program in
There is two way of which can be used in making a thread, that is :
- Making subclass of thread
To run thread, can be conducted by calling method start(). moment of Start() run, hence in fact run method() of class will be run. Become to make thread, have to define run method() at definition of class.
- implementation of Interface Runnable
Way of this represent the way of simplest in making thread. Runnable represent abstraction unit, that is class which is implementation this interface only enough function implementation of run(). In function implementation of run(), we will define instruction which developing a thread.
- Daemon And of User Thread
There is two Kinds of thread in Java, that is and daemon of user thread. Daemon thread represent thread which is its life cycle depend on especial thread or mains, so that if mains thread end, hence automatically daemon thread-thread also follow to end. While thread user measure up to differ, where if especial thread have, hence thread user will continue to be run.
- Sleep
Arranging thread to discontinue its process a moment and give opportunity at other process or thread.
- Interrupt
If wishing an thread to discontinue process, hence require to call interrupt method. Interrupt used to give signal at thread to discontinue its process.
- Synchronized
Synchronization is block or method owning addition of keyword synchronized, so that if run hence only one thread at one time which can run program block or method. Other Thread will await thread which is executing this method till finish. Synchronization mechanism important in the event of division of data and also resource among thread-thread. Synchronization also lock at data or resource which is processing.