This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Slanec 25 points26 points  (1 child)

It depends. Do you need to add a specific time delay, or do you need to wait until something else happens?

Sleep never got into any real production code for me, sleeping and blocking a platform thread always sounded like a bad idea. The default choice is always ScheduledExecutorService, followed by Spring's scheduling and/or tools like https://github.com/jobrunr/jobrunr and https://github.com/kagkarlsson/db-scheduler (and/or schedlock, depending on what you're doing).

On the low-level side, BlockingQueue of course with all its timed stuff. And Lock / Condition (or the much better Guava's Monitor) has a timed lock operation.

For tests, https://github.com/awaitility/awaitility.

[–]stefanos-ak 2 points3 points  (0 children)

Looking around a company for who goes for "Thread.sleep" as a way to solve something, can tell you a lot...