Thread Model of Java
Thread model of Java• All the class libraries are designed multithreading in  mind• Java uses threads to enable entire sys...
Thread model of Java contd..• Thread features   • Creation of threads   • Context switch   • Thread priorities   • Synchro...
Creation of Threads• Java provides two ways for creating threads by   • Extending Thread class   • Implementing Runnable i...
Context Switch• Switch from one thread to other• Two ways of context switch   • Thread can voluntarily relinquish control ...
Thread Priorities• Thread priorities are simple integers   • Ranging from 1 to 10   • A relative measure   • Higher the pr...
Synchronization• As threads introduces asynchronous behavior in Java  programs   • Synchronization is needed when two or m...
Synchronization contd..• There is no special monitor class in Java• Every object has its own implicit monitor• Two ways to...
Messaging• Java threads communicate with each other through  • notify() method  • wait() method                           ...
SummaryIn this class ,you have learnt• Thread basics       • Process       • Definition of thread       • Comparison of pr...
Frequently Asked Questions1. Compare a process and a thread2. Which methods are useful for messaging in Java3. Explain the...
Quiz1. Which one of the following is a thread ?   a) MS-Word   b) Windows Explorer   c) Spell checker in MS-Word   d) Note...
Quiz Contd..2. Which statement is true?   a) Thread does not depend on resources of any      process   b) Each Thread has ...
Home                    Exception Handling       Graphical User Interface Programming (GUI)Previous Java question papers w...
Upcoming SlideShare
Loading in...5
×

Thread model of java

5,450

Published on

1 Comment
1 Like
Statistics
Notes
No Downloads
Views
Total Views
5,450
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
64
Comments
1
Likes
1
Embeds 0
No embeds

No notes for slide

Thread model of java

  1. 1. Thread Model of Java
  2. 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. 3. Thread model of Java contd..• Thread features • Creation of threads • Context switch • Thread priorities • Synchronization • Messaging 3
  4. 4. Creation of Threads• Java provides two ways for creating threads by • Extending Thread class • Implementing Runnable interface 4
  5. 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. 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. 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. 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. 9. Messaging• Java threads communicate with each other through • notify() method • wait() method 9
  10. 10. SummaryIn 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. 11. Frequently Asked Questions1. Compare a process and a thread2. Which methods are useful for messaging in Java3. Explain the thread model of Java 11
  12. 12. Quiz1. Which one of the following is a thread ? a) MS-Word b) Windows Explorer c) Spell checker in MS-Word d) Notepad 12
  13. 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. 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
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×