Professional Documents
Culture Documents
IN
JAVA
CALLING RUN
• Invoking the run() method from main thread, the run() method goes onto the current
• The join method allows one thread to wait for the completion of another
• t.join(); causes the current thread to pause execution until t's thread terminate
SYNTAX
• In other words, it causes the currently running threads to stop executing until the
• The Thread class provides methods to change and get the name of a thread By
package com.codesjava;
class Main
{
public static void main (String[] args)
{
// creating two threads
ThreadNaming t1 = new ThreadNaming();
ThreadNaming t2 = new ThreadNaming();
t1.start();
t2.start();
}
}
Yield
● yield() basically means that the thread is not doing anything particularly
important and if any other threads or processes need to be run, they should run.
Otherwise, the current thread will continue to run.
● If processor finds any thread with higher or same priority then it will move
the current thread to Ready/Runnable state and give processor to other
thread and if not – current thread will keep executing.
LOGIC
import java.lang.*;
● Once a thread has executed yield method and there are many threads with
same priority is waiting for processor, then we can't specify which thread will
get execution chance first.
● The thread which executes the yield method will enter in the Runnable state
from Running state.
● Once a thread pauses its execution, we can't specify when it will get chance
again it depends on thread scheduler.
isAlive()
try {
c1.join(); // Waiting for c1 to finish
THANK YOU