Day-to-day the technologies are improving rapidly. The execution speed of processors is very fast and they provide the facility to execute multiple tasks at a time. So there are needs to utilize the resources sufficiently. So today it is main aim for developer that they should build the product which would use all the available resources.
There are two definition of a multitasking based on process and thread:
§ Process based: If in any system more than one program are executing concurrently, then it is called multitasking. e.g. Playing songs in media player while working with MS Word. Here media player is one program (or process) while word processor is different program (or process).
§ Thread based: if a single program perform two or more task simultaneously, then it is called multitasking. E.g. in Word Processor printing and formatting simultaneously. Here word processor is only one program but doing two tasks at a time. Java supports thread-based multitasking and provides high-level facilities for multithreaded programming.
A process is a self-contained running program with its own address space. Every process has its own separate address space in which it processes execute. In other words we can say that the each process has different context for execution. So there is no way to share the some information between two or more processes.
- Single sequential (one after another code) flow of control (or execution) within a program is called a thread. The thread is the line of execution of a program. The sequence of code executed for each task defines a separate path of execution, and is called a thread (of execution). Threads share the same address space or we can say that they have one context, so they can share data or information among multiple threads.
Every java program has at least one thread that is called the primary thread. a single threaded application can perform only one task at a time. In such a situation needs to complete one task so that another task can start. A process having more than one thread is said to be multi threaded. The multi threads in a program run at the same time perform different task and interact with each other.