Java: LockSupport.parkNanos vs Thread.sleep(…)

Readability: Thread.sleep has a pretty intuitive meaning. How would you describe (to another developer) your use of LockSupport.parkNanos? If that description primarily consists of “I want the current thread to sleep” then surely Thread.sleep is more descriptive.

The conciseness comes from the lack of interrupt handling – so create a wrapper method to do this if you want, which propagates the exception as a RuntimeException. Heck, if you’re creating a wrapper method, you can use either implementation, although another thread could of course unpark your “sleeping” thread in the same way as it could interrupt it…

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)