1

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

3 Answers 3

1

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
2
  • Since I have to carry a lot of data which is returned by the analysis of each program I either have to send them to the parent process using IPC or I have to write those data into a single file for each program which would result in about 20.000+ files... So basically there is no other soultion than IPC, right? Oct 21, 2013 at 19:11
  • I finally come up with running each program analysis as a single process which will communicate with the parent process to return it's results. I added the timeout functionality which will simply "destroy" the child process. All in all it was a lot of work but seems to be the best possible solution. Oct 22, 2013 at 11:32
0

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.

5
  • 1
    "The buildCallgraph() method is provided by SOOT and I have no chance to change it." Oct 21, 2013 at 17:47
  • @RobertHahn Duly noted and acknowledged.
    – An SO User
    Oct 21, 2013 at 17:48
  • I already know when the timeout occured (it's pretty simple). I just have now idea how to STOP the thread. Oct 21, 2013 at 17:48
  • hmmm.... usually the way is to interrupt() the thread object and inside the thread's run, check if the interrupt flag was set. If so, stop the processing. Now that SOOT is in the way, you have a bit of an issue.
    – An SO User
    Oct 21, 2013 at 17:50
  • @RobertHahn I am but a little child learning to crawl. There are people who have lost heir sanity coding and it reflects in their names. MadProgrammer be his name. Legend has it, he codes for 19 hours a day leaving his chair only to buy coding books and shoo away little children including me
    – An SO User
    Oct 21, 2013 at 17:52
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.