|
-
July 30th, 1999, 01:00 AM
#1
threads
class WatchDog implements Runnable
{
public WatchDog(Runnable r, int ms)
{
Thread t = new Thread(r);
t.start();
try
{
Thread.sleep(ms);
}
catch (InterruptedException e)
{
}
t.stop();
}
}
public class KillThread
{
public static void main(String[] args)
{
Analysis a = new Analysis();
WatchDog w = new WatchDog(a, 1000);
}
}
class Analysis implements Runnable
{
public void run()
{
while (true)
{
System.out.println("analyze ");
}
}
}
i have got this code from a site when i was studying about threads. this gives a bunch of compile errors which i was unable to fix. would somebody mind fixing it for me and explain ??
-
August 1st, 1999, 11:27 AM
#2
Re: threads
1. U have implemented Runnable for WatchDog class, but haven't written 'run' method in it.
2. Also I don't know if u r saving this code in one file or separate files. But if u don't want WatchDog and Analysis as public they must be in same file which has code for KillThread. Also name of the file must be 'KillThread.java' (as it is the only public class)
- UnicMan
http://members.tripod.com/unicman
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|