Question

I am using the SOOT framework for some static analysis. However, sometimes the analysis takes hours and I want to set a timeout to stop analysis and continue it with another program.

To achieve that kind of behavior I run the analysis in a thread:

thread = new Thread(new Runnable() { run(){ buildCallgraph(); } )};

!! The buildCallgraph() method is provided by SOOT and I have no chance to change it. !!

Currently I have no idea how to stop the thread. Interrupt won't work since buildCallgraph() is never checking if it's thread has been interrupted. Thread.stop() shouldn't be used.

So, does anyone has an idea how to terminate the Thread?

Regards Robert

Was it helpful?

Solution

There are good reasons for not using Thread.stop(), so how about a different approach: Instead of running the analysis in a separate thread, try running it as a separate program.

It'll mean a small performance hit, but pragmatically, task creation and serializing/deserializing the results shouldn't have a measurable effect compared to the scale of your current timing.

Unlike Thread.stop(), killing a program results in a clean exit since the jvm exits.

The downside to this is that the answers to your followup questions ("how do I start a task from within a java program", "how do I wait for the completion of another program", and "how do I programmatically kill another program") are all specific to operating system.

The upside is that they're already answered:

  1. How to start an external program inside a java program
  2. Java: wait for exec process till it exits
  3. Java tool/method to force-kill a child process

OTHER TIPS

How about you maintain a time-stamp of when you started the thread ?
Name the thread "I love BOOT framweork". Then, in a Timer, check if the Thread is still running.

If, in the Timer, you find out that the time taken is exceeding the time quantum, stop the thread.

With Java you cannot really terminate a thread preemptively. I always use the unix "timeout" command to shut down Soot after a certain time frame when I am doing such measurements. Obviously this will actually kill Soot without completing the run in a graceful fashion.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top