85 How Can We Define Multiple User Define Threads by Using Thread Class and Runnable Interface?

Code :

class MyThread implements Runnable
{
@Override
public void run()
{
for(int i=1;i<=10;i++)
System.out.println(i+".Run: "+Thread.currentThread().getName() );
}

public static void main( String args[] )
{
MyThread mt1 = new MyThread();
MyThread mt2 = new MyThread();

Thread t1 = new Thread(mt1);
Thread t2 = new Thread(mt2);

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


Output:



Previous
Next Post »