The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
April 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

re: thread

Posted by selvaraj on May 24, 2001 at 6:49 AM

> I want to create two threads one which prints date every second and another which prints my name every 5th second.
> Do i need to create two classes with saparate run methods?
> Pls. Help


No need to great two classes and two threads.u can print it in single thread itself.do the following steps

public void run(){
count=0;
for(;;){
//Display ur name
count++;
if(count>=5){
count=0;
//display the date
try{
Thread.Sleep(1000);
}catch(Exception e)){}
}
}





Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us