Get Job-ready: Java Course with 45+ Real-time Projects! - Learn Java
Program 1
package dataflair;
public class TestMain
{
public static void main(String[] args)
{
System.out.println("This is Main Thread: ");
System.out.println("Main Thread Priority: "+ Thread.currentThread().getPriority());
ChildThread1 mt1=new ChildThread1();
ChildThread2 mt2=new ChildThread2();
System.out.println("Child 1 Thread Priority: " + mt1.getPriority());
System.out.println("Child 2 Thread Priority: " + mt2.getPriority());
Thread.currentThread().setPriority(10);
System.out.println("After Change Main Thread Priority: "+ Thread.currentThread().getPriority());
System.out.println("After Change Child 1 Thread Priority: " + mt1.getPriority());
System.out.println("After Change Child 2 Thread Priority: " + mt2.getPriority());
// System.out.println("Minimum Priority value : "+Thread.MIN_PRIORITY);
// System.out.println("Normal Priority value: "+Thread.NORM_PRIORITY);
// System.out.println("Maximum Priority : "+Thread.MAX_PRIORITY);
//
// System.out.println("Main Thread Priority: "+ Thread.currentThread().getPriority());
// ChildThread1 mt1=new ChildThread1();
// ChildThread2 mt2=new ChildThread2();
// // System.out.println("Child Thread Priority: " + mt1.getPriority());
// mt1.setPriority(Thread.MAX_PRIORITY);
// mt1.start();
// mt2.setPriority(7);
// mt2.start();
// System.out.println("Child 1 Thread Priority: " + mt1.getPriority());
// System.out.println("Child 2 Thread Priority: " + mt2.getPriority());
// int i;
// for(i=1;i<=10;i++)
// {
// System.out.println("Main Thread : ");
// }
}
}
Program 2
package dataflair;
public class ChildThread1 extends Thread
{
public void run()
{
int i;
for(i=1;i<=10;i++)
{
System.out.println("Child Thread 1: ");
}
}
}
Program 3
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package dataflair;
/**
*
* @author admin
*/
public class ChildThread2 extends Thread
{
public void run()
{
int i;
for(i=1;i<=10;i++)
{
System.out.println("Child Thread 2: ");
}
}
}