File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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: 18115
    
    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: 3165
    
  10
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Execution time of a method.
 
Similar Threads
detecting delayed timer after server restart
Help me !! creat socket!
ResultSets Lose Second half of getString
Setting Request - Response Time Out Programatically
How to know that all the threads in pool are done with execution ?