SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Tendances (20)

Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
Thread model in java
Thread model in javaThread model in java
Thread model in java
 
14 relationship between processes
14 relationship between processes14 relationship between processes
14 relationship between processes
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
Java And Multithreading
Java And MultithreadingJava And Multithreading
Java And Multithreading
 
Java Threads
Java ThreadsJava Threads
Java Threads
 
Interface in java
Interface in javaInterface in java
Interface in java
 
Threads in JAVA
Threads in JAVAThreads in JAVA
Threads in JAVA
 
Threads .ppt
Threads .pptThreads .ppt
Threads .ppt
 
JVM
JVMJVM
JVM
 
Java Tokens
Java  TokensJava  Tokens
Java Tokens
 
Exception handling
Exception handlingException handling
Exception handling
 
Deadlock Prevention
Deadlock PreventionDeadlock Prevention
Deadlock Prevention
 
java interface and packages
java interface and packagesjava interface and packages
java interface and packages
 
L22 multi-threading-introduction
L22 multi-threading-introductionL22 multi-threading-introduction
L22 multi-threading-introduction
 
Java string handling
Java string handlingJava string handling
Java string handling
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
WHAT IS ABSTRACTION IN JAVA
WHAT IS ABSTRACTION IN JAVAWHAT IS ABSTRACTION IN JAVA
WHAT IS ABSTRACTION IN JAVA
 
Inter Process Communication
Inter Process CommunicationInter Process Communication
Inter Process Communication
 
JAVA ENVIRONMENT
JAVA  ENVIRONMENTJAVA  ENVIRONMENT
JAVA ENVIRONMENT
 

En vedette

Java multi threading
Java multi threadingJava multi threading
Java multi threadingRaja Sekhar
 
Multithreading In Java
Multithreading In JavaMultithreading In Java
Multithreading In Javaparag
 
java Unit4 chapter1 applets
java Unit4 chapter1 appletsjava Unit4 chapter1 applets
java Unit4 chapter1 appletsraksharao
 
Applet features
Applet featuresApplet features
Applet featuresmyrajendra
 
Java Course 10: Threads and Concurrency
Java Course 10: Threads and ConcurrencyJava Course 10: Threads and Concurrency
Java Course 10: Threads and ConcurrencyAnton Keks
 
Java Threads and Concurrency
Java Threads and ConcurrencyJava Threads and Concurrency
Java Threads and ConcurrencySunil OS
 
Java Thread Synchronization
Java Thread SynchronizationJava Thread Synchronization
Java Thread SynchronizationBenj Del Mundo
 
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 StructuresHitendra Kumar
 
Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in javaGoogle
 
Multi-threaded Programming in JAVA
Multi-threaded Programming in JAVAMulti-threaded Programming in JAVA
Multi-threaded Programming in JAVAVikram Kalyani
 
Thread presentation
Thread presentationThread presentation
Thread presentationAAshish Ojha
 
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...Anas Riahi
 
6.applet programming in java
6.applet programming in java6.applet programming in java
6.applet programming in javaDeepak Sharma
 
Applet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java AppletsApplet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java Appletsamitksaha
 

En vedette (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
 
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
 
Threads in Java
Threads in JavaThreads in Java
Threads in Java
 

Similaire à Thread model of java

Creation of threads
Creation of threadsCreation of threads
Creation of threadsmyrajendra
 
U4 JAVA.pptx
U4 JAVA.pptxU4 JAVA.pptx
U4 JAVA.pptxmadan r
 
Concurrency in java
Concurrency in javaConcurrency in java
Concurrency in javaAbhra Basak
 
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.pptxsandhyakiran10
 
Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)Martijn Verburg
 
Java Multi Thead Programming
Java Multi Thead ProgrammingJava Multi Thead Programming
Java Multi Thead ProgrammingNishant Mevawala
 
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.pptxDrYogeshDeshmukh1
 
BCA MultiThreading.ppt
BCA MultiThreading.pptBCA MultiThreading.ppt
BCA MultiThreading.pptsarthakgithub
 
Introduction to java by priti sajja
Introduction to java by priti sajjaIntroduction to java by priti sajja
Introduction to java by priti sajjaPriti Srinivas Sajja
 
Seattlerb why jruby
Seattlerb why jrubySeattlerb why jruby
Seattlerb why jrubysnacktime
 

Similaire à 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
 
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
 
Seattlerb why jruby
Seattlerb why jrubySeattlerb why jruby
Seattlerb why jruby
 

Plus de 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