SlideShare uma empresa Scribd logo
1 de 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

Mais conteúdo relacionado

Mais procurados

Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework Serhat Can
 
JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivityTanmoy Barman
 
Jdbc architecture and driver types ppt
Jdbc architecture and driver types pptJdbc architecture and driver types ppt
Jdbc architecture and driver types pptkamal kotecha
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handlingkamal kotecha
 
Java web application development
Java web application developmentJava web application development
Java web application developmentRitikRathaur
 
Basic of Multithreading in JAva
Basic of Multithreading in JAvaBasic of Multithreading in JAva
Basic of Multithreading in JAvasuraj pandey
 
Presentation on-exception-handling
Presentation on-exception-handlingPresentation on-exception-handling
Presentation on-exception-handlingNahian Ahmed
 
Java exception handling
Java exception handlingJava exception handling
Java exception handlingBHUVIJAYAVELU
 
Multithreading In Java
Multithreading In JavaMultithreading In Java
Multithreading In Javaparag
 
Collections In Java
Collections In JavaCollections In Java
Collections In JavaBinoj T E
 
Java Server Pages(jsp)
Java Server Pages(jsp)Java Server Pages(jsp)
Java Server Pages(jsp)Manisha Keim
 
Collection Framework in java
Collection Framework in javaCollection Framework in java
Collection Framework in javaCPD INDIA
 
Generics and collections in Java
Generics and collections in JavaGenerics and collections in Java
Generics and collections in JavaGurpreet singh
 
Thread priority in java
Thread priority in javaThread priority in java
Thread priority in javaRakesh Mittal
 

Mais procurados (20)

Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivity
 
Jdbc architecture and driver types ppt
Jdbc architecture and driver types pptJdbc architecture and driver types ppt
Jdbc architecture and driver types ppt
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
Java web application development
Java web application developmentJava web application development
Java web application development
 
Basic of Multithreading in JAva
Basic of Multithreading in JAvaBasic of Multithreading in JAva
Basic of Multithreading in JAva
 
Presentation on-exception-handling
Presentation on-exception-handlingPresentation on-exception-handling
Presentation on-exception-handling
 
Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
 
Servlets
ServletsServlets
Servlets
 
Java exception handling
Java exception handlingJava exception handling
Java exception handling
 
Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
 
Multithreading In Java
Multithreading In JavaMultithreading In Java
Multithreading In Java
 
Java Notes
Java NotesJava Notes
Java Notes
 
Collections In Java
Collections In JavaCollections In Java
Collections In Java
 
Java Server Pages(jsp)
Java Server Pages(jsp)Java Server Pages(jsp)
Java Server Pages(jsp)
 
Link state routing protocol
Link state routing protocolLink state routing protocol
Link state routing protocol
 
Collection Framework in java
Collection Framework in javaCollection Framework in java
Collection Framework in java
 
Generics and collections in Java
Generics and collections in JavaGenerics and collections in Java
Generics and collections in Java
 
Thread priority in java
Thread priority in javaThread priority in java
Thread priority in java
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 

Destaque

Java multi threading
Java multi threadingJava multi threading
Java multi threadingRaja Sekhar
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in javaRaghu nath
 
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 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
 

Destaque (20)

Threads in JAVA
Threads in JAVAThreads in JAVA
Threads in JAVA
 
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 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
 

Semelhante a Thread model of java

Semelhante a 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
 
Java buzzwords
Java buzzwordsJava buzzwords
Java buzzwords
 

Mais 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