Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force method run during specified interval of time

Tags:

java

I want to force method run for specified time.

 public Response run(Request req){
    //method runImpl must run during specified interval of time(for example for 10 secs)
    Response res = runImpl(req);
    return response;
    }

What is the best way to do this?Thanks!

like image 430
Martin Avatar asked Oct 26 '11 15:10

Martin


1 Answers

Try to use this:

poolExecutor = new ScheduledThreadPoolExecutor(1);
poolExecutor.scheduleAtFixedRate(
        new YourRunable(), startFrom/*10*/, startEvery/*5*/, TimeUnit.SECONDS);
like image 176
IronBCC Avatar answered Oct 17 '22 18:10

IronBCC