I think this can be mostly implemented in Java with bytecode re-writing which will check for the conditions on time to time.
Stopping the thread can still leave some of the stuff in indeterminate state if the thread has some resources it needs to release manually.