Chapter 2 - Multithreading.pptx [Autosaved].ppt - 1 2 We can walk talk breathe see hear smell all at the same time Computers can do this as well

Chapter 2 - Multithreading.pptx [Autosaved].ppt - 1 2 We...

This preview shows page 1 - 8 out of 48 pages.

Image of page 1
Image of page 2
We can walk, talk, breathe, see, hear, smell... all at the same time Computers can do this as well - download a file, print a file, receive email, run the clock Only computers that have multiple processors can truly execute multiple instructions concurrently Operating systems on single-processor computers create the illusion of concurrent execution by rapidly switching between activities, but on such computers only a single instruction can execute at once. Java makes concurrency available to you through the language and APIs. 3
Image of page 3
A thread is a control/flow/path of execution that exists within a process. Thread is portion of a program that can execute concurrently with other threads. Each thread is a statically ordered sequence of instructions. Sequential flow of control within a program Threads are being extensively used to express concurrency on both single and multiprocessors machines. Sharing a single CPU between multiple tasks (or "threads") in a way designed to minimize the time required to switch tasks. accomplished by sharing as much as possible of the program execution environment between the different tasks. Programming a task having multiple threads of control is called Multithreading or Multithreaded Programming . A multithreaded application contains separate threads of execution, where each thread o Has its own method-call stack and program counter 4
Image of page 4
o execute concurrently with other threads. o shares application-wide resources such as memory with other threads. In single-threaded applications lengthy activities must complete before others can begin which leads to poor responsiveness. In a multithreaded application, threads can be distributed across multiple processors (if available) so that multiple tasks execute concurrently and the application can operate more efficiently. Multithreading can also increase performance on single-processor systems that simulate concurrency—when one thread cannot proceed (because, for example, it is waiting for the result of an I/O operation), another can use the processor. The Java Virtual Machine (JVM) creates threads to run a program, the JVM also may create threads for performing housekeeping tasks such as garbage collection 5
Image of page 5
6 As shown in the above figure, thread is executed inside the process. There is context- switching between the threads. There can be multiple processes inside the OS and one process can have multiple threads.
Image of page 6
Multi-threading in java is a process of executing multiple threads simultaneously. Thread is basically a lightweight sub-process, a smallest unit of processing. Multiprocessing and multithreading, both are used to achieve multitasking. But we use multithreading than multiprocessing because threads share a common memory area. They don't allocate separate memory area so saves memory, and context-switching between the threads takes less time than process(see figure above).
Image of page 7
Image of page 8

You've reached the end of your free preview.

Want to read all 48 pages?

  • Summer '19
  • lencha
  • Subroutine,  Java

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes