CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: threads

  1. #1
    Join Date
    Jul 1999
    Posts
    7

    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 ??




  2. #2
    Join Date
    May 1999
    Location
    Pune, MH, India.
    Posts
    453

    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
  •  





Click Here to Expand Forum to Full Width

Featured