Re: Aborting Interpretting

Patrick Niemeyer <[email protected]> Mon, 14 Feb 2005 13:04:23 -0600
Newsgroups gmane.comp.java.beanshell.user,gmane.comp.java.beanshell.devel
Message-ID <[email protected]>
On Feb 14, 2005, at 10:33 AM, Alexey Zinger wrote:

> I thought one could simply terminate the thread it's running in.  I  
> haven't
> tried it though, but see no reason why this shouldn't work.  BSH  
> doesn't keep
> any state persisted on the hard drive that could get corrupted or  
> anything like
> that, right?

Script execution control will definitely be near the top of the list  
for new features.

In the interum, if you just want a course grained "abort" button,  
running the script in its own thread and using the deprecated Thread  
stop() method will probably do exactly what you want.

The reasons that Java's Thread stop() method was deprecated are more  
involved with fine grained recovery of locks and resources.  Normally  
you can't just halt a thread in the middle of an activity and expect  
synchronized code to come out in a consistent state.  With that said,  
since each BeanShell interpreter is almost entirely self contained  
(there are just a few ways to share static data across them) it  
probably won't affect you unless you are doing some elaborate  
application level synchronization between interpreters or between Java  
and the script interpreter.

Here is Sun's FAQ on Thread deprecation:

http://java.sun.com/j2se/1.4.2/docs/guide/misc/ 
threadPrimitiveDeprecation.html

So, in short - yes, using a Thread and stop() on your script is  
probably a fine solution until we offer a better one (hopefully soon).

If anyone disagrees and thinks that Thread stop() is just totally evil  
please feel free to chime in.


Pat



-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click