Lecture 20
Upcoming SlideShare
Loading in...5
×
 

Lecture 20

on

  • 150 views

Notes on core java

Notes on core java

Statistics

Views

Total Views
150
Views on SlideShare
150
Embed Views
0

Actions

Likes
0
Downloads
11
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Lecture 20 Lecture 20 Document Transcript

  • Core Java Debasish Pratihari Thread  A thread is the basic unit to which the operating system allocates processor time.  Threads are useful to execute more or less independent code segments concurrently of a program.  Is knows as light-weight process.  Threads are always owned and managed by operating system.  Every program has at least one thread. User Thread  A user thread has a life-time of its own.  It is not depended on the thread that creates it.  It can continue execution after the thread that created has ended. Daemon Thread  Is a background thread that sub-ordinate to the thread that creates it  When the thread that created the daemon thread ends, the daemon thread dies with it.  A thread can be set to daemon before it starts  Threads created from daemon thread are daemon by default. Lecture/core/thread1/20 Page #1 feel the Technology…
  • Core Java Debasish Pratihari Process  It has its own address space.  A process can’t access another process’s memory .  Each process provides the resources needed to execute a program.  Threads belongs to same process shares same address space.  A process has at least one thread of execution. Thread Objects:  Each thread is associated with an instance of the class Thread  There are two ways for using thread object  Directly controlling thread  Using executor Creating Thread  Provide a Runnable Object class Lakshya implements Runnable{ --}  Sub class Thread class Lakshya extends Thread{ --} Lecture/core/thread1/20 Page #2 feel the Technology…
  • Core Java Debasish Pratihari Thread State:  New Born State: When we create a Thread Object then a Thread is born.  Runnable State: When we call the start( ) method on a thread then thread is in the Runnable state i.e., the threads in Runnable state are all waiting in a queue for the availability of CPU attention or their turns to come.  Running State: When a thread got the time of CPU then it starts execution for a particular interval of time (time slice) this state is called as Running state.  Blocked state: A thread is in the blocked state when it is prevented to entered into Runnable state.  Dead state: This is the end of life of a thread, when a thread completes execution comes to the dead state. Also we can dead state by calling stop( ) method. New Born Start ( ) sleep ( ) Runnable State Stop ( ) Scheduling Dead State Lecture/core/thread1/20 Running State Block State after time-slice or yield( ) Page #3 feel the Technology…
  • Core Java  Debasish Pratihari A Thread enters into blocked state under the following situation.     By sleeping a thread. If a thread is waiting for I/O operation. If a thread is Interrupted. If a thread is waiting for lock available. Thread Life-Cycle 25% New Born start( ) start ( ) notify( )/ notifyAll ( ) Runnable State wait lock available I/O complete after t time Scheduling mechanism after time slice sleep( ) wait( ) Running State wait for Lock wait for I/O sleep( t ) B L O C K E D S T A T E Dead State Lecture/core/thread1/20 Page #4 feel the Technology…