Is it possible to stop a function's execution within a specified time in Java?
问题 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 回答1: 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