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

Multithreading In Java
Multithreading In JavaMultithreading In Java
Multithreading In Java
parag
 
String and string buffer
String and string bufferString and string buffer
String and string buffer
kamal kotecha
 
Transaction management
Transaction managementTransaction management
Transaction management
renuka_a
 

What's hot (20)

Multiple Access in Computer Network
Multiple Access in Computer NetworkMultiple Access in Computer Network
Multiple Access in Computer Network
 
Levels of Virtualization.docx
Levels of Virtualization.docxLevels of Virtualization.docx
Levels of Virtualization.docx
 
Thread
ThreadThread
Thread
 
Java Course 8: I/O, Files and Streams
Java Course 8: I/O, Files and StreamsJava Course 8: I/O, Files and Streams
Java Course 8: I/O, Files and Streams
 
Threads (operating System)
Threads (operating System)Threads (operating System)
Threads (operating System)
 
Multithreading
MultithreadingMultithreading
Multithreading
 
Process synchronization in Operating Systems
Process synchronization in Operating SystemsProcess synchronization in Operating Systems
Process synchronization in Operating Systems
 
Multi threading model
Multi threading modelMulti threading model
Multi threading model
 
Semi join
Semi joinSemi join
Semi join
 
Multithreading In Java
Multithreading In JavaMultithreading In Java
Multithreading In Java
 
Distributed DBMS - Unit 8 - Distributed Transaction Management & Concurrency ...
Distributed DBMS - Unit 8 - Distributed Transaction Management & Concurrency ...Distributed DBMS - Unit 8 - Distributed Transaction Management & Concurrency ...
Distributed DBMS - Unit 8 - Distributed Transaction Management & Concurrency ...
 
Command line-arguments-in-java-tutorial
Command line-arguments-in-java-tutorialCommand line-arguments-in-java-tutorial
Command line-arguments-in-java-tutorial
 
Transactions in dbms
Transactions in dbmsTransactions in dbms
Transactions in dbms
 
Java And Multithreading
Java And MultithreadingJava And Multithreading
Java And Multithreading
 
String and string buffer
String and string bufferString and string buffer
String and string buffer
 
String, string builder, string buffer
String, string builder, string bufferString, string builder, string buffer
String, string builder, string buffer
 
CS9222 ADVANCED OPERATING SYSTEMS
CS9222 ADVANCED OPERATING SYSTEMSCS9222 ADVANCED OPERATING SYSTEMS
CS9222 ADVANCED OPERATING SYSTEMS
 
Method overloading
Method overloadingMethod overloading
Method overloading
 
Chapter 4 data link layer
Chapter 4 data link layerChapter 4 data link layer
Chapter 4 data link layer
 
Transaction management
Transaction managementTransaction management
Transaction management
 

Viewers also liked

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

Similar to Thread model of java

Creation of threads
Creation of threadsCreation of threads
Creation of threads
myrajendra
 
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
 
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
 

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