Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage of java.util.Timer #15

Closed
agourlay opened this issue Jan 4, 2017 · 2 comments
Closed

Usage of java.util.Timer #15

agourlay opened this issue Jan 4, 2017 · 2 comments

Comments

@agourlay
Copy link

agourlay commented Jan 4, 2017

Hi,

I have a quick question regarding the implementation of Timeouts

It uses under the hood a java.util.Timer to schedule tasks to trigger timeouts.

After some reasearch I have found out that java.util.Timer could be replaced in most cases by a java.util.concurrent.ScheduledExecutorService as it performs better.

There is a bit of info in the javadoc and an interesting stackoverflow questions.

Therefore I performed the change in one my project that also used this kind of trick to design timeouts to see if it works.

I don't have a proper jmh benchmark to back this up but it does seem to perfom better for my use case.

Anyway, I just wanted to let you know about my research and to get your feedback regarding your choice of going with Timer in first place.

Thank you for the nice lib!

@johanandren
Copy link
Owner

The way the timer is used here is pretty much what ScheduledExecutorService does. The only logic triggered on it is creating/starting of a Future on the provided execution context, so it does not block the Timer thread, same goes for exceptions in the scheduled code-block, they end up failing the created future, not failing the Timer thread, so the problems described does not really apply as far as I can see. The statement about clock drift could be relevant but I couldn't find more details about Timer behaviour around that with a quick search though.

@agourlay
Copy link
Author

Thank you for taking the time to look into it.
You can close this issue if there is nothing else to do here 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants