Thread model of java

8,136 views

Published on

1 Comment
4 Likes
Statistics
Notes
No Downloads
Views
Total views
8,136
On SlideShare
0
From Embeds
0
Number of Embeds
12
Actions
Shares
0
Downloads
95
Comments
1
Likes
4
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

×