aspose file tools*
The moose likes Java in General and the fly likes Execution time of a method. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Execution time of a method." Watch "Execution time of a method." New topic
Author

Execution time of a method.

Shankara Sharma
Ranch Hand

Joined: Feb 06, 2012
Posts: 41
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
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

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

Joined: Feb 06, 2012
Posts: 41
@ 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

Joined: Aug 05, 2005
Posts: 3742
    
  16
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.

Joanne
 
 
subject: Execution time of a method.