Categories
Uncategorized

Multi threading

Write a JAVA Program to create a class (extending Thread) and use methods Thread class to change name, priority, — — of the current Thread and display the same.

class rectangle extends Thread

{

double length,breadth;

rectangle()

{

length=4;

breadth=3;

}

public void run()

{

//System.out.println(Thread.currentThread().getName());

Thread.currentThread().getPriority();

System.out.println(Thread.currentThread().getName()+length*breadth);

try{

Thread.sleep(1000);

}catch (Exception e){System.out.println(e);}

}

}

class triangle extends Thread

{

double height,breadth;

triangle()

{

height=4;

breadth=5;

}

public void run()

{

//System.out.println(Thread.currentThread().getName());

Thread.currentThread().getPriority();

System.out.println(Thread.currentThread().getName() +(0.5*height*breadth));

}

}

class circle extends Thread

{

double radius;

final double pie=3.14;

circle()

{

radius=12;

}

public void run()

{

//System.out.println(Thread.currentThread().getName());

Thread.currentThread().getPriority();

System.out.println(Thread.currentThread().getName()+(pie*radius));   

try{

Thread.sleep(1000);

}catch (Exception e){System.out.println(e);}

}

}

class area

{

public static void main(String args[])

{

rectangle r=new rectangle();

triangle t=new triangle();

circle c=new circle();

c.setName(“Area of Circle:”);

r.setName(“area of rectangle:”);

t.setName(“area of Traingle:”);

c.setPriority(Thread.MIN_PRIORITY);

r.setPriority(Thread.NORM_PRIORITY);

t.setPriority(Thread.MAX_PRIORITY);

t.start();

c.start();

r.start();

}

}

One reply on “Multi threading”

Comments are closed.