SlideShare a Scribd company logo
1 of 14
Thread Model of Java
Thread model of Java
• All the class libraries are designed multithreading in
  mind
• Java uses threads to enable entire system to be
  asynchronous
• Once a thread has been started
   • It can be suspended
   • Suspended thread can be resumed
   • It may be stopped


                                                           2
Thread model of Java contd..
• Thread features
   • Creation of threads
   • Context switch
   • Thread priorities
   • Synchronization
   • Messaging




                                          3
Creation of Threads
• Java provides two ways for creating threads by
   • Extending Thread class
   • Implementing Runnable interface




                                                   4
Context Switch
• Switch from one thread to other
• Two ways of context switch
   • Thread can voluntarily relinquish control by
       • Explicitly yielding
       • Sleeping
       • Blocking on pending I/O
       • Context switch is done by selecting the highest priority thread
   • Pre-emption
       • Occurs when a high priority enters while executing a low
         priority thread



                                                                           5
Thread Priorities
• Thread priorities are simple integers
   • Ranging from 1 to 10
   • A relative measure
   • Higher the priority – brighter the chances of getting
     executed first




                                                             6
Synchronization
• As threads introduces asynchronous behavior in Java
  programs
   • Synchronization is needed when two or more
     threads work with a shared resource
   • ‘Monitor’ feature is used in Java to implement
     Synchronization
   • Monitors are used mutually exclusive




                                                        7
Synchronization contd..
• There is no special monitor class in Java
• Every object has its own implicit monitor
• Two ways to show synchronization
   • synchronized methods
   • synchronized statements




                                              8
Messaging

• Java threads communicate with each other through

  • notify() method

  • wait() method




                                                     9
Summary
In this class ,you have learnt
• Thread basics
       • Process
       • Definition of thread
       • Comparison of process and thread
       • Thread model of Java
       • Features of Java that implemented threads




                                                     10
Frequently Asked Questions
1. Compare a process and a thread
2. Which methods are useful for messaging in Java
3. Explain the thread model of Java




                                                    11
Quiz
1. Which one of the following is a thread ?
   a) MS-Word
   b) Windows Explorer
   c) Spell checker in MS-Word
   d) Notepad




                                              12
Quiz Contd..

2. Which statement is true?
   a) Thread does not depend on resources of any
      process
   b) Each Thread has its own heap memory
   c) A Thread share heap with other threads
   d) None
Home
                    Exception Handling
       Graphical User Interface Programming (GUI)
Previous Java question papers with Answers for polytechnic
                      diploma (jntu)
             OCT/NOV-2012 QUESTION PAPER
                  April / May 2012 c-09
              October/ November-2011 c-09
                   April/ May 2011 c-09
                 APRIL/MAY-2011 (C-05)
               Internal Lab question paper
               External Lab question paper
                BTECH JNTU LAB MANUAL
                        Lab practice
               Core java interview questions

More Related Content

What's hot

Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
Abhilash Nair
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
Tech_MX
 

What's hot (20)

Semophores and it's types
Semophores and it's typesSemophores and it's types
Semophores and it's types
 
System calls
System callsSystem calls
System calls
 
CPU Scheduling in OS Presentation
CPU Scheduling in OS  PresentationCPU Scheduling in OS  Presentation
CPU Scheduling in OS Presentation
 
Exception Handling in JAVA
Exception Handling in JAVAException Handling in JAVA
Exception Handling in JAVA
 
MULTI THREADING IN JAVA
MULTI THREADING IN JAVAMULTI THREADING IN JAVA
MULTI THREADING IN JAVA
 
Process of operating system
Process of operating systemProcess of operating system
Process of operating system
 
JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivity
 
Characteristics of OOPS
Characteristics of OOPS Characteristics of OOPS
Characteristics of OOPS
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
 
INTRODUCTION TO JSP,JSP LIFE CYCLE, ANATOMY OF JSP PAGE AND JSP PROCESSING
INTRODUCTION TO JSP,JSP LIFE CYCLE, ANATOMY OF JSP PAGE  AND JSP PROCESSINGINTRODUCTION TO JSP,JSP LIFE CYCLE, ANATOMY OF JSP PAGE  AND JSP PROCESSING
INTRODUCTION TO JSP,JSP LIFE CYCLE, ANATOMY OF JSP PAGE AND JSP PROCESSING
 
Hill climbing algorithm
Hill climbing algorithmHill climbing algorithm
Hill climbing algorithm
 
File Handling in Java Oop presentation
File Handling in Java Oop presentationFile Handling in Java Oop presentation
File Handling in Java Oop presentation
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Register allocation and assignment
Register allocation and assignmentRegister allocation and assignment
Register allocation and assignment
 
Semaphores
SemaphoresSemaphores
Semaphores
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Process state in OS
Process state in OSProcess state in OS
Process state in OS
 
QSpiders - Jdk Jvm Jre and Jit
QSpiders - Jdk Jvm Jre and JitQSpiders - Jdk Jvm Jre and Jit
QSpiders - Jdk Jvm Jre and Jit
 
OOP java
OOP javaOOP java
OOP java
 
JVM
JVMJVM
JVM
 

Viewers also liked

Multithreading In Java
Multithreading In JavaMultithreading In Java
Multithreading In Java
parag
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
Raghu nath
 
Applet features
Applet featuresApplet features
Applet features
myrajendra
 
Java Thread Synchronization
Java Thread SynchronizationJava Thread Synchronization
Java Thread Synchronization
Benj Del Mundo
 
6.applet programming in java
6.applet programming in java6.applet programming in java
6.applet programming in java
Deepak Sharma
 

Viewers also liked (20)

Java multi threading
Java multi threadingJava multi threading
Java multi threading
 
Threads concept in java
Threads concept in javaThreads concept in java
Threads concept in java
 
Multithreading In Java
Multithreading In JavaMultithreading In Java
Multithreading In Java
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
java Unit4 chapter1 applets
java Unit4 chapter1 appletsjava Unit4 chapter1 applets
java Unit4 chapter1 applets
 
javathreads
javathreadsjavathreads
javathreads
 
Applet features
Applet featuresApplet features
Applet features
 
Applets in java
Applets in javaApplets in java
Applets in java
 
Java Course 10: Threads and Concurrency
Java Course 10: Threads and ConcurrencyJava Course 10: Threads and Concurrency
Java Course 10: Threads and Concurrency
 
Java Threads and Concurrency
Java Threads and ConcurrencyJava Threads and Concurrency
Java Threads and Concurrency
 
Java Applet and Graphics
Java Applet and GraphicsJava Applet and Graphics
Java Applet and Graphics
 
Java Thread Synchronization
Java Thread SynchronizationJava Thread Synchronization
Java Thread Synchronization
 
Java Performance, Threading and Concurrent Data Structures
Java Performance, Threading and Concurrent Data StructuresJava Performance, Threading and Concurrent Data Structures
Java Performance, Threading and Concurrent Data Structures
 
Fundamentals
FundamentalsFundamentals
Fundamentals
 
Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in java
 
Multi-threaded Programming in JAVA
Multi-threaded Programming in JAVAMulti-threaded Programming in JAVA
Multi-threaded Programming in JAVA
 
Thread presentation
Thread presentationThread presentation
Thread presentation
 
Rapport PFE : Réalisation d'une application web back-office de gestion pédago...
Rapport PFE : Réalisation d'une application web back-office de gestion pédago...Rapport PFE : Réalisation d'une application web back-office de gestion pédago...
Rapport PFE : Réalisation d'une application web back-office de gestion pédago...
 
6.applet programming in java
6.applet programming in java6.applet programming in java
6.applet programming in java
 
Applet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java AppletsApplet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java Applets
 

Similar to Thread model of java

Creation of threads
Creation of threadsCreation of threads
Creation of threads
myrajendra
 
chapter_one_Introduction_to_Object_Oriented_Programming_OOP.pptx
chapter_one_Introduction_to_Object_Oriented_Programming_OOP.pptxchapter_one_Introduction_to_Object_Oriented_Programming_OOP.pptx
chapter_one_Introduction_to_Object_Oriented_Programming_OOP.pptx
FiromsaDine
 
Concurrency in java
Concurrency in javaConcurrency in java
Concurrency in java
Abhra Basak
 

Similar to Thread model of java (20)

Creation of threads
Creation of threadsCreation of threads
Creation of threads
 
U4 JAVA.pptx
U4 JAVA.pptxU4 JAVA.pptx
U4 JAVA.pptx
 
chapter_one_Introduction_to_Object_Oriented_Programming_OOP.pptx
chapter_one_Introduction_to_Object_Oriented_Programming_OOP.pptxchapter_one_Introduction_to_Object_Oriented_Programming_OOP.pptx
chapter_one_Introduction_to_Object_Oriented_Programming_OOP.pptx
 
Thread
ThreadThread
Thread
 
Thread
ThreadThread
Thread
 
Concurrency in java
Concurrency in javaConcurrency in java
Concurrency in java
 
8.-OBJECT-ORIENTED-PROGRAMMING-USING-JAVA-Multithreading.pptx
8.-OBJECT-ORIENTED-PROGRAMMING-USING-JAVA-Multithreading.pptx8.-OBJECT-ORIENTED-PROGRAMMING-USING-JAVA-Multithreading.pptx
8.-OBJECT-ORIENTED-PROGRAMMING-USING-JAVA-Multithreading.pptx
 
java Features
java Featuresjava Features
java Features
 
Java Online Training
Java Online TrainingJava Online Training
Java Online Training
 
Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)
 
Java Multi Thead Programming
Java Multi Thead ProgrammingJava Multi Thead Programming
Java Multi Thead Programming
 
Java Classroom Training
Java Classroom TrainingJava Classroom Training
Java Classroom Training
 
Java concurrency
Java concurrencyJava concurrency
Java concurrency
 
Unit No 4 Exception Handling and Multithreading.pptx
Unit No 4 Exception Handling and Multithreading.pptxUnit No 4 Exception Handling and Multithreading.pptx
Unit No 4 Exception Handling and Multithreading.pptx
 
Java and the JVM
Java and the JVMJava and the JVM
Java and the JVM
 
BCA MultiThreading.ppt
BCA MultiThreading.pptBCA MultiThreading.ppt
BCA MultiThreading.ppt
 
15 threads
15 threads15 threads
15 threads
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
Java threading
Java threadingJava threading
Java threading
 
Introduction to java by priti sajja
Introduction to java by priti sajjaIntroduction to java by priti sajja
Introduction to java by priti sajja
 

More from myrajendra (20)

Data type
Data typeData type
Data type
 
Hibernate example1
Hibernate example1Hibernate example1
Hibernate example1
 
Jdbc workflow
Jdbc workflowJdbc workflow
Jdbc workflow
 
2 jdbc drivers
2 jdbc drivers2 jdbc drivers
2 jdbc drivers
 
3 jdbc api
3 jdbc api3 jdbc api
3 jdbc api
 
4 jdbc step1
4 jdbc step14 jdbc step1
4 jdbc step1
 
Dao example
Dao exampleDao example
Dao example
 
Sessionex1
Sessionex1Sessionex1
Sessionex1
 
Internal
InternalInternal
Internal
 
3. elements
3. elements3. elements
3. elements
 
2. attributes
2. attributes2. attributes
2. attributes
 
1 introduction to html
1 introduction to html1 introduction to html
1 introduction to html
 
Headings
HeadingsHeadings
Headings
 
Forms
FormsForms
Forms
 
Css
CssCss
Css
 
Views
ViewsViews
Views
 
Views
ViewsViews
Views
 
Views
ViewsViews
Views
 
Starting jdbc
Starting jdbcStarting jdbc
Starting jdbc
 
Properties
PropertiesProperties
Properties
 

Thread model of java

  • 2. Thread model of Java • All the class libraries are designed multithreading in mind • Java uses threads to enable entire system to be asynchronous • Once a thread has been started • It can be suspended • Suspended thread can be resumed • It may be stopped 2
  • 3. Thread model of Java contd.. • Thread features • Creation of threads • Context switch • Thread priorities • Synchronization • Messaging 3
  • 4. Creation of Threads • Java provides two ways for creating threads by • Extending Thread class • Implementing Runnable interface 4
  • 5. Context Switch • Switch from one thread to other • Two ways of context switch • Thread can voluntarily relinquish control by • Explicitly yielding • Sleeping • Blocking on pending I/O • Context switch is done by selecting the highest priority thread • Pre-emption • Occurs when a high priority enters while executing a low priority thread 5
  • 6. Thread Priorities • Thread priorities are simple integers • Ranging from 1 to 10 • A relative measure • Higher the priority – brighter the chances of getting executed first 6
  • 7. Synchronization • As threads introduces asynchronous behavior in Java programs • Synchronization is needed when two or more threads work with a shared resource • ‘Monitor’ feature is used in Java to implement Synchronization • Monitors are used mutually exclusive 7
  • 8. Synchronization contd.. • There is no special monitor class in Java • Every object has its own implicit monitor • Two ways to show synchronization • synchronized methods • synchronized statements 8
  • 9. Messaging • Java threads communicate with each other through • notify() method • wait() method 9
  • 10. Summary In this class ,you have learnt • Thread basics • Process • Definition of thread • Comparison of process and thread • Thread model of Java • Features of Java that implemented threads 10
  • 11. Frequently Asked Questions 1. Compare a process and a thread 2. Which methods are useful for messaging in Java 3. Explain the thread model of Java 11
  • 12. Quiz 1. Which one of the following is a thread ? a) MS-Word b) Windows Explorer c) Spell checker in MS-Word d) Notepad 12
  • 13. Quiz Contd.. 2. Which statement is true? a) Thread does not depend on resources of any process b) Each Thread has its own heap memory c) A Thread share heap with other threads d) None
  • 14. Home Exception Handling Graphical User Interface Programming (GUI) Previous Java question papers with Answers for polytechnic diploma (jntu) OCT/NOV-2012 QUESTION PAPER April / May 2012 c-09 October/ November-2011 c-09 April/ May 2011 c-09 APRIL/MAY-2011 (C-05) Internal Lab question paper External Lab question paper BTECH JNTU LAB MANUAL Lab practice Core java interview questions