53509879-37977380-JAVA-Threads - Concurrent Programming in...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Concurrent Programming in Java Mrs. S.S.Jamsandekar Department of Computer Science Shivaji University JAVA Threads Concurrent Programming in Java Two basic units of execution processes Threads Processes A process has a self-contained execution environment. A process generally has a complete, private set of basic run-time resources; in particular, each process has its own memory space. Processes are often seen as synonymous with programs or applications. Java virtual machine run as a single process. Java application can create additional processes using a ProcessBuilder object . JAVA Threads Threads Threads are sometimes called lightweight processes Threads also provide an execution environment Creating a new thread requires fewer resources than creating a new process. Thread cannot exist on its own (threads exist within a process ) Threads share the process's resources, including memory and open files A thread is an independent path of execution within a program. (collection of statements that execute in a specific order) Every application has at least one thread or several( main Thread) JAVA Threads Multithreaded execution is an essential feature of the Java platform Multithreading refers to two or more tasks executing concurrently within a single program . . A Java program can have many threads, and these threads can run concurrently, either asynchronously or synchronously . Multithreading has several advantages over Multiprocessing Threads are lightweight compared to processes Threads share the same address space and therefore can share both data and code Context switching between threads is usually less expensive than between processes Cost of thread intercommunication is relatively low that that of process intercommunication Threads allow different tasks to be performed concurrently. Thread Life Cycle Model Thread Life Cycle Model Thread Life Cycle Model New state After the creations of Thread instance the thread is in this state but before the start() method invocation. At this point, the thread is considered not alive. Runnable (Ready-to-run) state A thread start its life from Runnable state. A thread first enters runnable state after the invoking of start() method but a thread can return to this state after either running, waiting, sleeping or coming back from blocked state also. On this state a thread is waiting for a turn on the processor. Running state A thread is in running state that means the thread is currently executing. There are several ways to enter in Runnable state but there is only one way to enter in Running state: the scheduler select a thread from runnable pool....
View Full Document

This note was uploaded on 12/14/2011 for the course ENPM 603 taught by Professor Kumar during the Winter '09 term at Indian Institute of Technology, Kharagpur.

Page1 / 27

53509879-37977380-JAVA-Threads - Concurrent Programming in...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online