Programmatically Restart a Java Application. We Recommend These Resources Today I'll talk about a famous problem : restarting a Java application.
It is especially useful when changing the language of a GUI application, so that we need to restart it to reload the internationalized messages in the new language. Some look and feel also require to relaunch the application to be properly applied. A quick Google search give plenty answers using a simple : 1.Runtime.getRuntime().exec("java -jar myApp.jar"); 2.System.exit(0); This indeed basically works, but this answer that does not convince me for several reasons :1) What about VM and program arguments ? Overall, something that works fine for some test, sandbox use, but not a generic and elegant way in my humble opinion. Ok, so my purpose here is to implement a method : 1.public static void restartApplication(Runnable runBeforeRestart) throws IOException { Let's start by looking at each point and find a way to answer them in an elegant way (let's say the most elegant way that I found).
Java. The new Java Caching Standard (javax.cache) This post explores the new Java caching standard: javax.cache.
How it Fits into the Java Ecosystem This standard is being developed by JSR107, of which the author is co-spec lead. JSR107 is included in Java EE 7, being developed by JSR342. Java EE 7 is due to be finalised at the end of 2012. But in the meantime javax.cache will work in Java SE 6 and higher and Java EE 6 environments as well as with Spring and other popular environments. JSR107 has draft status. Java tip: How to read files quickly. Technologies: Java 5+ Java has several classes for reading files, with and without buffering, random access, thread safety, and memory mapping. Some of these are much faster than the others. This article benchmarks 13 ways to read bytes from a file and shows which ways are the fastest.
A quick review of file reading classes Let's quickly run through several ways to open and read a file of bytes in Java. FileInputStream with byte reads FileInputStream f = new FileInputStream( name ); int b; long checkSum = 0L; while ( (b=f.read()) ! FileInputStream opens a file by name or File object. FileInputStream uses synchronization to make it thread-safe. FileInputStream with byte array reads FileInputStream f = new FileInputStream( name ); byte[] barray = new byte[SIZE]; long checkSum = 0L; int nRead; while ( (nRead=f.read( barray, 0, SIZE )) ! FileInputStream does an I/O operation on every read and it synchronizes on all method calls to make it thread-safe. BufferedInputStream with byte reads Benchmarks.