KEMBAR78
Java 11 Program | PDF
0% found this document useful (0 votes)
9 views1 page

Java 11 Program

The document contains a Java program that demonstrates the use of threads by implementing the Runnable interface. It creates a class 'mythread' that prints the current thread's name and a counter from 1 to 5, pausing for 500 milliseconds between each print. The main class 'ThreadExample' initializes and starts three threads using the same 'mythread' instance.

Uploaded by

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

Java 11 Program

The document contains a Java program that demonstrates the use of threads by implementing the Runnable interface. It creates a class 'mythread' that prints the current thread's name and a counter from 1 to 5, pausing for 500 milliseconds between each print. The main class 'ThreadExample' initializes and starts three threads using the same 'mythread' instance.

Uploaded by

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

public class mythread implements Runnable

{
public void run()
{
for (int i=1; i<=5; i++)
{
System.out.println(Thread.currentThread().getName()+"i is"+i);
try
{
Thread.sleep(500);
}
catch (InterruptedException e)
{
System.out.println(e.getMessage());
}
}
}
}
class ThreadExample
{
public static void main(String[] args) {
// TODO Auto-generated method stub
mythread myThread = new mythread();
Thread t1=new Thread (myThread);
Thread t2=new Thread (myThread);
Thread t3=new Thread (myThread);
t1.start ();
t2.start ();
t3.start ();
}

You might also like