Immutable Blocks July 24, 2018
This sample shows you how to use the Immutable class. The immutable class represents persistent storage that can be accessed at the low level as an array of primitive types. This example shows the use of an array of longs. The long values in this application are date values that represent when the application was started.
package immutablesample; import com.integpg.system.Immutable; import java.util.Date; public class ImmutableSample { public static void main(String[] args) { // get an array of long values that represent the last 5 boot times long[] lastFiveBootTimes = Immutable.getLongArray("BootTimes"); // if the array does not already exist then create an array of 5 long values if (lastFiveBootTimes == null) lastFiveBootTimes = Immutable.createLongArray("BootTimes", 5); // shift the previous 4 boot times for (int i = 4; i > 0; i--) { lastFiveBootTimes[i] = lastFiveBootTimes[i - 1]; } // assign the most recent boot time lastFiveBootTimes[0] = System.currentTimeMillis(); // loop through our last five boot times and print them in a readable format for (int i = 0; i < 5; i++) { long bootTime = lastFiveBootTimes[i]; if (bootTime > 0) { System.out.println(new Date(bootTime)); } } } }