Jun 4, 2007

Multithreading in Java:

class mt implements Runnable
{
Thread t;
mt()
{
t = new Thread(this, "Demo thread");
t.start();
}

public void run()
{
try
{
for(int i=1;i<=10;i++)
{
System.out.println(i);
t.sleep(1000);
}
}
catch(InterruptedException e)
{
System.out.println("Thread is interrupted");
}
}
};

class th
{
public static void main(String[] args)
{
mt t = new mt();
try
{
for (int i=2;i<=20;i=i+2)
{
System.out.println(i);
Thread.sleep(500);
}
}
catch(InterruptedException e)
{
}
}
}

No comments:

Post a Comment

Infolinks In Text Ads

Total Pageviews

Powered by Blogger.

Dont Forget To Follow Us

Blog Archive