Archive for the ‘Java.lang.Thread’ Category

PostHeaderIcon Java Thread – simple example

//*****Thread 1

public class Thread1 implements Runnable
{
public void run()
{
System.out.println (“Thread1″);
}
}//*****

//Thread 2*****

public class Thread2 implements Runnable
{
public void run()
{
System.out.println (“Thread2″);
}

}
//*****
//Thread 3*****

public class Thread3 implements Runnable
{
public void run()
{
System.out.println (“Thread3″);
}
}

//Thread Testpublic class ThreadTest
{
public static void main (String[] args)
{
Thread1 tr1 = new Thread1();
Thread2 tr2 = new Thread2();
Thread3 tr3 = new Thread3();
Thread t = new Thread(tr1);
Thread t2 = new Thread(tr2);
Thread t3 = new Thread(tr3);

t.start();
try
{
Thread.sleep(10*1000);
}
catch (Exception e)
{
System.out.println(e);
}
t2.start();
t3.start();
}
}

Adsense