How do I limit the maximum execution time when executing a java app from command line, like this:
java -Xmx10G -cp /weka/weka.jar weka.classifiers.trees.J48 -t
/test/test-vector.arff -d /test/test.model
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I don’t believe there’s anything built into Java to do this for you. Options:
As an example of the latter, in bash on Unix-like systems you could use
ulimit -t [seconds]before starting the process.EDIT: As noted in comments, it’s not clear how graceful such a shutdown with ulimit would be – whether the threads would be killed in a sufficiently polite way to allow finally blocks to execute etc. That’s probably something worth testing out.
EDIT: Again as per comments, ulimit limits the CPU time, not the overall wall time. This may or may not be what you’re after – it depends if your process is CPU-bound.