This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Multitasking can be done if and only if we have multiprocessor.
Threads, actually executes the tasks in the call stack just by pausing one task for some seconds and executing other tasks and again executes the paused task and so on....
So, this means it didn't executes the tasks simultaneously / parallel but it makes the user to feel so.
Do we need threads actually ? Or do i need to know more about threads ?
Exploiting the raw power of a multiprocessor /multicore system is one of the benefits of using a multithreaded solution, sure.
Probably the most obvious one. There are benefits for single-processor / single-core systems as well.
For instance, ensuring responsiveness of a (Swing) user interface for example, by executing long-lived tasks in a thread separate from the EDT.
Another reason could be simplicity, which might seems at odds with the 'inherent complexity' of using threads.
For instance, it might be possible to reduce a singe complex asynchronous sequence of operations to multiple synchronous operations of reduced complexity, each running in a spearate thread and interacting at specific points.
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Let's not forget that not all tasks are processor intensive. For example, you can certainly have lots of threads doing i/o -- network, files, database, etc. -- and it is perfectly fine for these threads to share the processor. Basically, one thread can be working while many others are waiting for data. This is certainly better than a thread waiting for data, while all the others are waiting for it to finish.