How to perform single task by multiple threads?
If you have to perform single task by many threads, have only one run() method.For example: |
Output:task one task one task one
Output:task one task one
Note: Each thread run in a separate callstack.
How to perform multiple tasks by multiple threads (multitasking in multithreading)?
If you have to perform multiple tasks by multiple threads,have multiple run() methods.For example: |
Output:task one task two
Same example as above by annonymous class that extends Thread class:
Program of performing two tasks by two threadsOutput:task one task two
Same example as above by annonymous class that implements Runnable interface:
Program of performing two tasks by two threadsOutput:task one task two
No comments:
Post a Comment