AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Stopping a Thread

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help
View previous topic :: View next topic  
Author Message
David Levitan
Guest





PostPosted: Fri Apr 23, 2004 2:37 pm    Post subject: Stopping a Thread Reply with quote



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
Back to top
Steve Horsley
Guest





PostPosted: Fri Apr 23, 2004 7:57 pm    Post subject: Re: Stopping a Thread Reply with quote



David Levitan wrote:
Quote:
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

Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.