• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Execution time of a method.

 
Shankara Sharma
Ranch Hand
Posts: 46
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I want to write an implementation in java where i need to call a particular method(Ex: process) and this method will return me a properties object. I need to check the execution time of the the process method. I need to wait for this method to return value for a specific period of time(Ex : timeout). After the time got expired i need to proceed without waiting for process() method to return a value.

public void test(int timeout)
{
Properties prop= process();
}

Thanks,

Shankar
 
Paul Clapham
Sheriff
Pie
Posts: 20166
24
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's exactly what the FutureTask class is for. Check it out.

(See how it's underlined? Follow the link to the API documentation.)
 
Shankara Sharma
Ranch Hand
Posts: 46
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@ Paul : Thanks Paul

I want to use a method called get(long timeout, TimeUnit unit) in FutureT API. I have given timeout as 10 and unit as MILLISECONDS. When i call this method, will this method wait for 10 MILLISECONDS for every FutureTask even though the FutureTask execution is completed in 5 MILLISECONDS or if the future task is completed in 5 MILLISECONDS will this get method returns the result?

Thanks,

Shankar.
 
Joanne Neal
Rancher
Pie
Posts: 3742
16
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shankara Sharma wrote:I want to use a method called get(long timeout, TimeUnit unit) in FutureT API. I have given timeout as 10 and unit as MILLISECONDS. When i call this method, will this method wait for 10 MILLISECONDS for every FutureTask even though the FutureTask execution is completed in 5 MILLISECONDS or if the future task is completed in 5 MILLISECONDS will this get method returns the result?

Isn't that something you could test yourself ? Set the timeout to (say) a minute and see if the method call returns after a minute or more or less immediately. You'll learn a lot more by experimentation than by just asking questions.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic