Home > Archive > Java Help > April 2004 > Stopping a Thread
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| David Levitan 2004-04-23, 11:53 am |
| Hi,
I'm currently trying to resolve some problems I am having with a grading
program I am using to grade submisions for a Java class. The students
are writing a compiler that I then use to compile specific test cases
and then execute them in a custom virtual machine. However, not all of
these submissions work perfectly, and often they hang for some unknown
reason on certain test cases. This is a problem with the student's code,
but I can't change the submissions so that they're more friendly. I am
already using a custom classloader for each instance of the compilation,
and am wrapping the actual compilation in a seperate thread. However, I
would like to be able to kill the thread 30 seconds after starting it.
At the moment I am starting the thread (which simply calls the compile
method in the student's submission), then wait 30 seconds for it to
quit, and then try to interrupt the thread (which doesn't work). I have
also tried stop and suspend with the same lack of success. I have tried
closing the I/O stream the submission operates on (well, it's not
actually a stream, but close enough), but that hasn't helped either.
Does anyone have any idea how to stop such a thread?
Thank you very much for any help,
David Levitan
| |
| Steve Horsley 2004-04-27, 10:11 pm |
| David Levitan wrote:
> Hi,
> I'm currently trying to resolve some problems I am having with a grading
> program I am using to grade submisions for a Java class. The students
> are writing a compiler that I then use to compile specific test cases
> and then execute them in a custom virtual machine. However, not all of
> these submissions work perfectly, and often they hang for some unknown
> reason on certain test cases. This is a problem with the student's code,
> but I can't change the submissions so that they're more friendly. I am
> already using a custom classloader for each instance of the compilation,
> and am wrapping the actual compilation in a seperate thread. However, I
> would like to be able to kill the thread 30 seconds after starting it.
> At the moment I am starting the thread (which simply calls the compile
> method in the student's submission), then wait 30 seconds for it to
> quit, and then try to interrupt the thread (which doesn't work). I have
> also tried stop and suspend with the same lack of success. I have tried
> closing the I/O stream the submission operates on (well, it's not
> actually a stream, but close enough), but that hasn't helped either.
> Does anyone have any idea how to stop such a thread?
> Thank you very much for any help,
> David Levitan
You don't. Google this newsgroup for lots of discussion on this subject.
I suggest that you execute a separate process like this:
Process p = Runtime.getRuntime().exec("java blah blah blah");
And then later you can do...
p.destroy(); // is it destroy? Can't remember for sure
Don't forget to drain the Process's stdout and stderr streams
or it may block forever.
HTH
Steve
|
|
|
|
|