what is the difference between multitasking and
multithreading?
Answer Posted / sonika
Multithreading
Up to now, we have talked about multiprogramming as a way to allow multiple programs being resident in main memory and (apparently) running at the same time. Then, multitasking refers to multiple tasks running (apparently) simultaneously by sharing the CPU time. Finally, multiprocessing describes systems having multiple CPUs. So, where does multithreading come in?
Multithreading is an execution model that allows a single process to have multiple code segments (i.e., threads) run concurrently within the “context” of that process. You can think of threads as child processes that share the parent process resources but execute independently. Multiple threads of a single process can share the CPU in a single CPU system or (purely) run in parallel in a multiprocessing system
Why should we need to have multiple threads of execution within a single process context?
Well, consider for instance a GUI application where the user can issue a command that require long time to finish (e.g., a complex mathematical computation). Unless you design this command to be run in a separate execution thread you will not be able to interact with the main application GUI (e.g., to update a progress bar) because it is going to be unresponsive while the calculation is taking place.
Of course, designing multithreaded/concurrent applications requires the programmer to handle situations that simply don’t occur when developing single-threaded, sequential applications. For instance, when two or more threads try to access and modify a shared resource (race conditions), the programmer must be sure this will not leave the system in an inconsistent or deadlock state. Typically, this thread synchronization is solved using OS primitives, such as mutexes and sempaphores.
| Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
Can each java object keep track of all the threads that want to exclusively access it?
What is map java?
Describe the term diamond problem.
What is default locale java?
What is early binding and late binding in java?
How do you create a bulleted list?
Explain about fail fast iterators in java?
Should database connections be singleton?
What is the difference between heap and stack memory?
What is the use of a copy constructor?
How do you add an element to a set in java?
What is the purpose of java?
Will the jvm load the package twice at runtime?
what is the volatile modifier for? : Java thread
What is linked hashset and its features?