java - Call a method after timeout occurs -


i have tried implement timeout in code. want start timeout , if timeout occurs should call method.

pseudocode way:       in bar function             start timeout    ---> ( @ background, if timeout occurs call foo() )        in foo function             cancel timeout             print 

how call method after timeout occurs?

edit: should have ability re-start timeout.

there lot of different ways achieve it...

the simplest might use java.util.timer allow schedule timertask executed @ time in future...

you take @ scheduledexecutorservice believe it's executor equivalent.


Comments