1 / 11

Java Threads

Java Threads. What is Thread. Threading is a facility to allow multiple activities to coexist within a single process . Specialized form of Multitasking.

amos-baker
Télécharger la présentation

Java Threads

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Java Threads

  2. What is Thread • Threading is a facility to allow multiple activities to coexist within a single process. • Specialized form of Multitasking. • Java is the first mainstream programming language to explicitly include threading within the language itself, rather than treating threading as a facility of the underlying operating system.

  3. What is Thread • A process can support multiple threads, which appear to execute simultaneously and asynchronously to each other • Threads are independent, concurrent paths of execution through a program. • Each Thread has • Stack • Program Counter • Local Variables

  4. Thread Sharing • Threads within a process are less insulated from each other than separate processes are. They share memory, file handles. • Does not depend upon Operating System.

  5. Every Java program uses threads • Every Java program has at least one thread -- the main thread. When a Java program starts, the JVM creates the main thread and calls the program's main() method within that thread.

  6. Why use threads • Make the UI more responsive • Take advantage of multiprocessor systems • Simplify modeling • Perform asynchronous or background processing.

  7. Thread States

  8. Thread Priority • JVM selects to run a Runnable thread with the highest priority. • All Java threads have a priority in the range 1-10. • Top priority is 10, lowest priority is 1. Normal priority by default is 5. • Thread.MIN_PRIORITY - minimum thread priority • Thread.MAX_PRIORITY - maximum thread priority • Thread.NORM_PRIORITY- maximum thread priority

  9. Thread Scheduling • The JVM schedules using a preemptive , priority based scheduling algorithm. • All Java threads have a priority and the thread with he highest priority is scheduled to run by the JVM. • In case two threads have the same priority a FIFO ordering is followed.

  10. Thread Methods

  11. Thread Methods

More Related