Introduction: -
- concurrent units in Java methods named run.
- Code can be in concurrent execution with other search methods and with the main method.
- Process in Which the run methods execute is called a thread.
- Lightweight task
- They all run in the same address space.
- Different from Ada Tasks-> heavyweight threads.
2 ways: -
- To define a class with Run Method
- define a subclass of the predefined class Thread and override its run method
- if a new subclass has a Necessary natural parent then Defining it as a subclass of the thread will not work.
- In search situation we define a sub class inherits from its natural parent did and implement the Runnable interface.
Runnable: -
- Provides Run Method Protocol
- any class implements Runnable must define did run
- An Object of the class implements Runnable That is passed to the thread constructor
- Ada - Tasks Can Be Either actors or server task and communicate with eachother through accept clauses
- Java methods are run all actors
- Except for the join method and through shared data.
- not the natural parent of any OtherClass
- Provides some services for its subclasses
- not related in any natural way to Their computational purposes
- only OtherClass available for creating concurrent Java programs
- includes 5 constructors and a collection of methods and constants
- Run Method Describes the action of the thread
- Always overriden by subclasses of threads
begin(): -
- starts its thread as a concurrent unit by calling its run ();
- call to start is unusual in fact, control returns immediately to the caller Which then Continues its execution in parallel with the newly started run ().
- EC.,
class MyThread extends Threads
{
public void run () {} ..................
}
......................................
Thread Myth = new MyThread ();
MyTh.start ();
- When An Application Program Execution begins a new thread is Treated and main is called.
- All Java Application Program runs in threads
- When a program has multiple threads - schedule gives equal size time slices to each thread in round-robin fashion ready Assuming all of thesis have the same priority
- Provides several methods for controlling the execution of threads
- yield () - no parameters; - a request from the running thread to surrender the processor voluntarily; - thread is put immediately into the task ready queue making it ready to run; - if there are no other ready threads with priority higher than one just yielded the processor so it may be the next thread to get the processor.
No comments:
Post a Comment