Four Small Java/Coffee Tips That Result in Better Performance (and Better Taste)

By: William Phelps | Senior Technical Architect

 

It’s really no secret that it’s little things that often yield the biggest results.

As you are reading this article, chances are that you are perhaps drinking a cup of coffee. There are quite a few small things about coffee that you may or may not know.

  • – Simply adding cream to your coffee will keep the coffee warmer about 20 percent longer. This occurrence is similar in nature to the effect that allows warm water to be frozen into ice cubes faster than cold water. Try it and see.
  • – Adding a small pinch of salt to your coffee will cut down on the acidity of the coffee, and results in a much smoother cup of coffee. Add the salt to the coffee pot if you brew by the pot, or to your cup if you like a single-serve variety.  (I personally use kosher salt for this trick, not regular table salt… you’ll likely use too much with the table salt.)
  • – Coffee grounds are an excellent fertilizer source for house plants. I’d imagine the amount found in a regular single-serving cup or Keurig “K” cup would be ideal for small potted plants.
  •  – The first webcam was implemented by Cambridge University to monitor a coffee pot. The coffee was disappearing very quickly, so a webcam was used to monitor when the pot was finished brewing so people could get a cup.

Rather than going to the extreme of putting a camera on a pot, some folks opt to go out for their coffee fix.  Have you ever noticed that the cup of coffee you buy in-store at Starbucks tastes so much better when brewed in the shop, than from the same bag of grounds that you bought in the shop, and then took it home and brewed it yourself?  This is likely due to a handful of reasons, but the biggest reason is probably the tuning of the exact process that the average barista follows.

The very same tuning principle applies to your Java program. “Compile once, run anywhere” code is still very dependent on the environment in which it’s deployed. Think of Java as the coffee whereas the Java Virtual Machine (“JVM”) is the coffee pot that comes in the Java Development Kit (“JDK”). A better “pot” and the process of handling said pot will result in more consistent results. There are a lot of “coffee pot“ manufacturers but some basic setups are all the same.

  • –  “Avoid installing Java into a file system location with spaces in the path.”Primarily a Windows issue, the Windows Java installer suggests a default installation path in the “Program Files” directory. This is a problem for many programs when your programs start looking for jars to add in the class loader. Unless the program was coded to wrap the classpath in quotes, your program will fail in very odd ways that is hard to debug. While this is predominantly a Windows problem, the same thing can happen on other operating systems.  A coffee pot will have a proper storage “space” in your home/office. Ditch the space however in your install paths.
  • –  “Install the JVM/JDK into a generic path location.”While this may seem counterintuitive, once the basic installation is done, the process of updating the JVM/JDK in the future becomes very simple. Seeing the version of the JDK in a file path is a weird comfort for some people, but having to edit numerous files to update the location reference is fraught with issues, and in some cases may be impossible.  It’s simply easier for other folks to find the “working” coffee pot if it’s always stored in the same place. Multiple pots can exist on a server, but this approach makes it clearer which pot is being used.
  • –  “Change/update the random number generator source.”Have you ever got tired of waiting for the coffee pot to heat up? Sometimes a JVM is really sluggish in performing because of insufficient entropy on a server. This is a somewhat complex topic, but in essence, some operating systems rely on basic I/O to generate input for random number generation. If the generation is slow, and multiple processes are waiting for a number, your program can seemingly hang, when in reality it’s just waiting in the queue.

There is a small change that can be made in the JVM to change the random number generation process to look at another source. In the jdk’s jre/lib/security folder, find the java.security file. Search for the line that references “secure.random”.

Add a . to the setting as shown, and restart your processes that use the JVM.

This trick has been shown to significantly improve startup times in WebLogic server.

  • – “Reinstall any certificates from the old JVM to the new JVM.”Finally, if the coffee pot is getting an upgrade, some of the “attachments” may still be needed. This is true of certificates that may have been installed in the cacerts file of the old JVM. Before upgrading the JDK make a copy of the existing cacerts file. Then you can reimport the certificates by basically merging the deltas from the old cacerts file into the new version.

This command will only insert/import certificates that exist in the old cacerts file, but not in the new cacerts file. This is really handy when it’s not known which exact certificates have changed over time.

It’s the little things that make both a smooth cup of coffee and a smooth-running JVM.

 

Want more Java tips? Contact us today!