25/02/25 ---------- Multithreading ---------------- Q)What are the similarities between multitasking and multithreading? =>Both are meant for performing multiple tasks concurrently. =>Both are meant for optimum utlization of CPU. =>In both the cases Operating System Support is required for time sharing/slicing and context switching. Q)What are the differences between multitasking and multithreading? =>process based multiple concurrent tasks performing mechanism is multitasking. "n" processes for "n" concurrent tasks. =>thread based (sub process based) multiple concurrent tasks performing mechanism is multithreading. 1 process for "n" concurrent tasks. =>No programming effort is required for multitasking.Operating system implicitly provides the support. Where as, for multithreading programming effort is required. Q)What is a thread? =>A single sequential flow of control is nothing but a thread. OR =>An independent path of execution is known as a thread. =>In a Java application, a thread is represented as an object(instance). Note:- A thread is a sub process Q)What is a single threaded application? =>An application is said to be single threaded if it has only one sequential flow of control (only one independent path of execution. Q)What is the limitation of a single threaded application? =>In a single threaded application, we can't perform multiple parallel tasks. Q)What is a multithreaded application? =>An application is said to be multi threaded if it has muliple sequential flows of control(multiple independent paths of execution). =>A Multithreaded application can perform multiple concurrent jobs. Q)What is multithreading? =>The mechanism of making an application multithreaded is nothing but multithreading. Q)How to make an application multithreaded? Step 1:- Write a Java class that extends java.lang.Thread class or that implements java.lang.Runnable interface Step 2:- Override run method in the above class. =>write task performing code in run method either directly or indirectly Note:- run method is known as the body of the thread. Step 3:- Create as many thread objects as the application requires. Step 4:- activate the threads.