Want a code to terminate my program after a time interval

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.