I want to know how to stop a specified function’s execution within a specified time in java.
For example: I may call a function called print_data(). If it takes more time to execute, I will have to stop that function’s execution.
Is it possible to stop the execution like this?
Thanks in advance
You could add some checks to your function: save the timestamp when function started working and then periodically checking that inside the function, throwing an exception if function takes too long.
This is the cleanest way to accomplish such task in Java.