Single Thread and Multiple Thread

What is difference between Single Thread and Multiple Thread?
Explain Single Thread Model Vs. Multi thread model. Support your answer with practical example?

Showing Answers 1 - 3 of 3 Answers

Prathiba

  • Apr 21st, 2016
 

A single threaded java program executes in the following manner: Every Java program has at least one thread of control. When a Java program is executed; the execution starts from main() method and statements inside main() are executed sequentially one after the other. In a single threaded environment, at a time only one statement is executed and no parallel execution takes place. When a Java program starts, the JVM creates a thread -- the main thread and calls the programs main() method within that thread to execute statements contained inside body of main() method.

Multi-threading comes into picture when we have requirement to execute two or more methods in parallel. In case we need more than one function to be executed in parallel, we have to create threads at our own to run them concurrently. When two or more functions run in parallel, they are called concurrent modules and this feature of programming language is called concurrency. Java language has built-in support for concurrency and provides APIs for creating, using and managing threads to harness multi-threading feature of the language.

Multi-threading in Java: Languages such as C, C++ do not have built-in multi-threading capabilities and must therefore make non portable calls to operating system multi-threading primitives. Java, on the other hand, includes multi-threading primitives as part of the language itself and as part of its libraries. This facilitates manipulating threads in a portable manner across platforms.

Advantages of Multi-threading
Multi-threaded applications run actions in parallel; therefore, small tasks have not to wait for lengthy tasks to finish. They can run in parallel to big and time consuming tasks. In single-threaded environment one task must complete before other can begin. In a multi-threaded application, threads can be distributed across multiple processors (if they are available) so that multiple tasks are performed concurrently and the application can operate more efficiently. Multi-threading can also increase performance on single-processor systems that simulate concurrency—when one thread cannot proceed, another can use the processor.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions