enfrptes

sendassignment@tutorspoint.com

Thread Priorities Homework Help

Tutorspoint.com is an excellent site, which caters to all queries of programming assignment help, regarding java assignments related to topics of Thread Priorities homework help with a clear solution.

Since all the programming assignment writing help is offered at reasonable rates, Tutorspoint expert service is highly recommended by students worldwide from many universities of U.S. America, Australia, Canada, Germany, Ireland, and Denmark.

 

What is Thread Priorities

A) Properties are integer values which are range from 1 to 9.

B) indicates the lowest priority and 9 indicates the highest priority.

C) Thus, when we have multiple threads in a wait state and if we call notify () in the current thread, then the thread with the highest priority will be notified first.

D)  Priorities should be assigned to the corresponding threads before calling the start () method.

E)  To assign the priorities to threads, we use the set priority () method. It is a non-static function that accepts an integer value (1 to 9) as an argument.

F)  Priority concept can be used only when there is a possibility for threads to enter the wait state.

 

Consider the following scenarios

t1, t2, t3 --------- threads

t1. Set priority (4);

t2. Set priority (9);

t3. Set priority (7);

Running state                     wait state t1, t2

t3

Run ()

{

Notify ();   which thread will it notify?

 

Explanation

a) We have three threads t1, t2 and t3 and their priorities are set as shown above.

b) Let us assume that t1 and t2 are in a wait state and t3 is running state.

c) Now, if notify () is encountered in the run () method of t3 then it obviously notifies t2 because t2 has the highest priority.

d) If we don’t set a priority to a thread explicitly, then every thread will have a default priority. The default priority is none other than the priority of the parent thread from which the current thread is spawned.

e) As an absolute value, a priority is meaningless: a higher priority thread does not run any faster than lowest priority thread if it is the only thread running.

f) Instead, a thread's priority is used to decide when to switch from one running thread to the next. This is called a context switch.

 

The rules are determined a context switch is simple

A) A thread can voluntarily relinquish control. In these scenarios, all other threads are examined, and the highest priority thread that is really to run given the CPU time.

B) A thread can be preempted by the highest priority thread that does not yield the processor is simply preempted by the highest priority thread.

Basically as soon as the highest priority thread wants to run, it does. This is called preemptive multitasking.

 

Thread Priorities Homework Help