5.6. LockFactory Configuration

The Lucene Directory can be configured with a custom locking strategy via LockingFactory for each index managed by Hibernate Search.
Some locking strategies require a filesystem level lock, and may be used on RAM-based indexes. When using this strategy the IndexBase configuration option must be specified to point to a filesystem location in which to store the lock marker files.
To select a locking factory, set the hibernate.search.<index>.locking_strategy option to one the following options:
  • simple
  • native
  • single
  • none

Table 5.8. List of available LockFactory implementations

name Class Description
simple org.apache.lucene.store.​SimpleFSLockFactory
Safe implementation based on Java's File API, it marks the usage of the index by creating a marker file.
If for some reason you had to kill your application, you will need to remove this file before restarting it.
native org.apache.lucene.store.​NativeFSLockFactory
As does simple this also marks the usage of the index by creating a marker file, but this one is using native OS file locks so that even if the JVM is terminated the locks will be cleaned up.
This implementation has known problems on NFS, avoid it on network shares.
native is the default implementation for the filesystem, filesystem-master and filesystem-slave directory providers.
single org.apache.lucene.store.​SingleInstanceLockFactory
This LockFactory doesn't use a file marker but is a Java object lock held in memory; therefore it's possible to use it only when you are sure the index is not going to be shared by any other process.
This is the default implementation for the ram directory provider.
none org.apache.lucene.store.​NoLockFactory
Changes to this index are not coordinated by a lock.
The following is an example of locking strategy configuration:
hibernate.search.default.locking_strategy = simple
hibernate.search.Animals.locking_strategy = native
hibernate.search.Books.locking_strategy = org.custom.components.MyLockingFactory