0% found this document useful (0 votes)
4 views3 pages

Java Thread Creation and Execution Example

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Java Thread Creation and Execution Example

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Q.

WAP in java to illustrate creating and executing threads in java:

import [Link].*;

class X extends Thread

public void run()

for(int i=0;i<5;i++)

{ [Link]("Thread X:" + i); }

[Link]("Thread X finished\n");

class Y extends Thread

public void run()

for(int i=0;i<5;i++)

{ [Link]("Thread Y:" + i); }

[Link]("Thread Y finished\n");

class Z extends Thread

public void run()

for(int i=0;i<5;i++)

{ [Link]("Thread Z:" + i); }

[Link]("Thread Z finished\n");
}

class creatingrunningthread

public static void main(String args[])

[Link]("MAIN thread started\n");

X tx=new X(); Y ty=new Y(); Z tz=new Z();

[Link](); [Link](); [Link]();

[Link]("MAIN thread finished");

Output:

C:\Users\INDIA\Desktop>javac [Link]

C:\Users\INDIA\Desktop>java creatingrunningthread

MAIN thread started

MAIN thread finished

Thread Z:0

Thread Z:1

Thread Z:2

Thread Y:0

Thread Y:1

Thread Y:2

Thread X:0

Thread Z:3

Thread Y:3

Thread X:1
Thread X:2

Thread X:3

Thread X:4

Thread X finished

Thread Z:4

Thread Z finished

Thread Y:4

Thread Y finished

You might also like