Site icon WebArtDeveloper

How to Create Multiple Threads in Core Java

In this tutorial how to create Multiple Threads in Core Java  is shown.

Code:

Thread3.java

class MyThreads extends Thread
{
MyThreads(String name)
{
setName(name);
}

public void run()
{
try
{
for(int i=0;i<10;i++)
{
Thread.sleep(2000);
System.out.print(” “+getName()+” “+String.valueOf(i));
}
}
catch(InterruptedException ie)
{
ie.printStackTrace();
}
}
}

class ThreadDemo
{
public static void main(String args[])
{
MyThreads t1 = new MyThreads(“T1”);
MyThreads t2 = new MyThreads(“T2”);

t1.start();
t2.start();
}
}

https://youtu.be/MPZrejrBh3g

Exit mobile version