Legacy Knowledge Base
Published Sep. 10, 2025

Groovy script to clear the stale data in the lock_ and backgroundtask tables

Written By

Thanga Meena

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

Legacy Article

You are viewing an article from our legacy "FastTrack" publication program, made available for informational purposes. Articles in this program were published without a requirement for independent editing or verification and are provided"as is" without guarantee.

Before using any information from this article, independently verify its suitability for your situation and project.

Issue

  • Groovy script to clear the stale data in the lock_ and backgroundtask tables

Environment

  • Liferay DXP 7.2+

Resolution

  • In the log, similar to the below info may be thrown which shows that there may be some stale data is available which might not be allowing to perform the task. If there are stale data related to the reported action, those should be removed first to move to the next step of the investigation if the issue persists.
  • For example, Reindexing is not completed. In that case, please check both lock_ and backgroundtask tables and see if there are stale data related to reindexing. If yes, delete those entries by following the below procedures and please make sure you have gone through the below important notes before proceeding with it.
  • 2020-03-30 23:41:31.795 INFO  [liferay/background_task-3][BackgroundTaskMessageListener:146] Unable to acquire lock, queuing background task 188137692
  • Navigate to Control Panel --> Server Administrator --> Script page
    • Select the "Groovy" script. Paste the following script and click on Execute.
  • For Lock table entry: lockId should be replaced with the respective Id with the className of the stale data entry you want to delete it.
com.liferay.portal.lock.service.LockLocalServiceUtil.deleteLock(long lockId)
out.println(Deleted Lock Entry);
  • For BackgroundTask table entry: long backgroungTaskId should be replaced by the respective BID value with the className of the stale data entry you want to delete it.
com.liferay.portal.background.task.service.BackgroundTaskLocalServiceUtil.deleteBackgroundTask(long backgroundTaskId)
out.println(Deleted BackgroundTask Entry);
  • After executing the above scripts, delete the temporary directories in the Liferay bundle and start the server.
  • Note: Please take the DB dump before performing the above action item. And test the reported behavior in the testing environment and if it's working fine then move to the production as per your discretion.

Additional Information

Did this article resolve your issue ?

Legacy Knowledge Base