0

any simple program for single thread with timer in java.

that thread will run with particular time.

i am new to this thread.

thanks in advance

1 Answer 1

1

You'll want a ScheduledExecutorService, which can be obtained from one of the static factory methods on Executors.

Check out:

http://download.oracle.com/docs/cd/E17409_01/javase/6/docs/api/java/util/concurrent/Executors.html

http://download.oracle.com/docs/cd/E17409_01/javase/6/docs/api/java/util/concurrent/ScheduledExecutorService.html

Sign up to request clarification or add additional context in comments.

4 Comments

hi i want to call a one function, the name of function is addition(), this function take some time for execute. some time this is take over time for execute, so i would like to avoid the function execute more time, in that time i would like to end the function execution, the addition function executes in while loop, so i would like to set 10 seconds for each time calling the function. can u understand what is my problem?
Do you want to call addition repeatedly or just once? Also, can't you just test the current time in addition's loop? while (System.currentTimeMillis() < startTime + (1000 * 10)) { ... }
i called repeatedly,but the input of the addition function is different,so what will i do?
Could you provide a bit more context of what you're trying to achieve? Also, are you able to modify the addition method? I.e. could you put in the check I mentioned above?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.