Java developers tend to use the ‘java.util.UUID#randomUUID()’ API to generate a UUID (Universally Unique Identifier) number (i.e., ‘b8bbcbed-ca07-490c-8711-5118ee0af2f9’). Under certain circumstances, using this API can affect your application’s availability. Let’s discuss this API in this post with a real-world example.
How Does the ‘java.util.UUID#randomUUID()’ API Work?
java.util.UUID#randomUUID() API internally uses ‘entropy‘ in the operating system to generate a unique number. What does ‘entropy’ mean? The Linux kernel uses certain techniques like a user’s mouse movements, variance in the hardware fan noise, variance in the noise of the device drivers, etc. to generate random numbers. When there is a lack of ‘entropy’ in the operating system, then random number generation will slow down. When there is a slowdown, application threads that are calling this ‘java.util.UUID#randomUUID()’ API call will be put in a BLOCKED state, and they wouldn’t be able to progress further.