417
references to them. Unlike regular Java objects, their lifetime can extend beyond a single
instance of the Java virtual machine and beyond machine restarts.
Because the contents of persistent objects are retained, it’s important to maintain
data consistency of objects even in the face of crashes and power failures. Persistent
collections and other objects in the library offer persistent data consistency at the Java
method level. Methods, including field setters, behave as if the method’s changes to
persistent memory all happen or none happen. This same method-level consistency can
be achieved with developer-defined classes using a transaction API offer by PCJ.
PCJ uses the libpmemobj library from the Persistent Memory Development Kit
(PMDK) which we discussed in Chapter 7. For additional information on PMDK, please
visit https://pmem.io/ and https://github.com/pmem/pmdk.
Using PCJ in Java Applications
To import this library into an existing Java application, include the project’s target/
classes directory in your Java classpath and the project’s target/cppbuild directory in
your java.library.path. For example:
$ javac -cp .:/pcj/target/classes
$ java -cp .:/pcj/target/classes \
-Djava.library.path=/pcj/target/cppbuild
There are several ways to use the PCJ library:
1. Use instances of built-in persistent classes in your applications.
2. Extend built-in persistent classes with new methods.
3. Declare new persistent classes or extend built-in classes with
methods and persistent fields.
PCJ source code examples can be found in the resources listed in the following:
• Introduction to Persistent Collections for Java – https://github.
com/pmem/pcj/blob/master/Introduction.txt
• Code Sample: Introduction to Java∗ API for Persistent Memory
Programming – https://software.intel.com/en-us/articles/
code-sample-introduction-to-java-api-for-persistentmemory-programming
Appendix d JAvA for persistent MeMory