1 Multi-Threading Models Many-to-One Model One-to-One Model ...

errorhandleΛογισμικό & κατασκευή λογ/κού

18 Νοε 2013 (πριν από 3 χρόνια και 6 μήνες)

63 εμφανίσεις

1

Multi-Threading Models



Many
-
to
-
One Model

One
-
to
-
One Model

Many
-
to
-
Many Model










Advantage(s):








Advantage(s):






Advantage(s):







Disadvantage(s):








Disadvantage(s):








Disadvantage(s):







2

Java Virtual Machines



3

Thread Libraries





4

Java Threads

The Java language and its API provide a rich set of features for the creation and management of
threads.

All Java programs comprise of at least a single thread of control that begins in the program’s main()
method.

Creating a thread in a Java program
1. Define a class that implements the Runnable interface

2. This class must then define a run() method

3. Create an instance of the Thread object and pass the Constructor a Runnable object

4. Call the start() method for the Thread object to do the following:

a. Allocate the memory and initialize a new thread in the JVM

b. The start() method calls the run() method, making the thread eligible to be run by
the JVM

The code implementing the run method is what runs as a separate
thread

(see multi-threaded Producer-Consumer program)
5

Java Thread States


























(see multi-threaded Summation program)