Categories
Java

LockObtainFailedException: Lock obtain timed out: SimpleFSLock@ [Issue/Explain]

Let’s me start from a scenario of a Java (Hibernate, Spring App)/tomcat application that would give you as myself, the error as stated in the subject above.

To reproduce

In some cases, as you do as following steps:

  • Build with clean install
  • Start Tomcat as normal
  • Stop Tomcat
  • And Start Tomcat again
  • You got an error with LockObtainFailedException

The error message

org.apache.lucene.store.LockObtainFailedException: Lock obtain timed out: SimpleFSLock@C:\Users\youruser\YourProject-1.0-SNAPSHOT\index\com.yourproject.model.MyModel\write.lock

 

Work Around Solution

Here is my first solution, I noticed each time I got the error

  • Each before start any tomcat, you need to run: mvn clean install
  • Then can start tomcat as normal

 

Exactly Cause & Temporary Solution

What’s the exactly issue I really found out. It is because of your search index in configuration of file: hibernate.properties

app.search.index.basedir=\${user.home}/${project.build.finalName}/index
hibernate.search.default.directory_provider=filesystem
hibernate.search.default.locking_strategy=simple
hibernate.search.default.exclusive_index_use=true
hibernate.search.lucene_version=LUCENE_35
hibernate.search.analyzer=org.apache.lucene.analysis.en.EnglishAnalyzer
hibernate.search.worker.batch_size=100

According to the doc of LockFactory as in one document of RedHat, the strategy config with simple said that:

If for some reason you had to kill your application, you will need to remove this file before restarting it.

So that for my temporary solution, I consider to disable the index for awhile in my development environment and keep above setting for my production environment.

hibernate.search.default.locking_strategy=none

Real Solution

I still need more flexible solution which is better than above “Work Around Solution” & “Temporary Solution” for my development environment, nor deleting the file for each restarting the tomcat.

Please drop in comment if you have some experiences about this issue.

One reply on “LockObtainFailedException: Lock obtain timed out: SimpleFSLock@ [Issue/Explain]”

Vote this up, if you believed that the issue can be solved as I stated in above article as summary as:

  • Re-build project: mvn clean install
  • Disable locking strategy with none method (hibernate.search.default.locking_strategy=none)
  • Follow the doc. delete the index folder for each restart tomcat

Leave your comment in reply if you have more than this.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.