So I have a method which takes upto 4 hours to execute. I need to stop this method within the first 30 mins of execution and have the available results upto that 30 mins of time only. Can someone help me with this? I have tried many things to terminate my method but found no luck. I want the solution in Java.

Recommended Answers

All 2 Replies

Show (relevant) parts of your code. It'll make it easier to get suggestions.

commented: I have a execute() method. In this method we are trying to execute a script(.sh file) which is taking almost 4 hours +0

Build the process with ProcessBuilder. Start the process. Star at 30 minute Timer. Get the available results as they are written to the process' output stream (may need to code the script to display results as they are created). When the Timer fires terminateForcibly() the process.

commented: Thank you. Can I have one example for this approach to understand correctly in order to decide whether I can use this approach. +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.