<<<<<<< HEAD lock_timeout | H2 | SQLDoc
Skip to main content

lock_timeout

1. LOCK_TIMEOUT Function

======= lock_timeout | H2 Function | SQLDoc

lock_timeout

1. LOCK_TIMEOUT Function

>>>>>>> 9d19b1c8cb744c8e86d5c15b74d8b5f719ad62be

The LOCK_TIMEOUT function in H2 database is used to set the timeout value for waiting to acquire a lock on a database object.

2. Syntax

The syntax for the LOCK_TIMEOUT function in H2 database is as follows:

LOCK_TIMEOUT(timeout)

Arguments

  • timeout: The timeout value in milliseconds. It should be a positive integer representing the number of milliseconds to wait for acquiring a lock.

Return

  • The LOCK_TIMEOUT function does not return any value. It is used to set the timeout value for lock acquisition.

3. Notes

  • The LOCK_TIMEOUT function in H2 database is used to set the timeout value globally for the current session.
  • When a database object is locked, other sessions attempting to acquire a lock on the same object will wait for the specified timeout period. If the lock cannot be acquired within the timeout, an exception will be thrown.
  • Specifying a value of 0 for the timeout means that the lock acquisition will not wait and will throw an exception immediately if the lock cannot be acquired.
  • The timeout value set using the LOCK_TIMEOUT function affects all subsequent lock acquisition operations within the session.

4. Examples

Here are a few examples demonstrating the usage of the LOCK_TIMEOUT function in H2 database:

Example 1 - Setting the lock timeout value to 5000 milliseconds:

LOCK_TIMEOUT(5000);

In this example, the lock timeout value is set to 5000 milliseconds (5 seconds) for the current session. Any subsequent lock acquisition operations will wait for a maximum of 5 seconds to acquire the lock before throwing an exception.

Example 2 - Setting the lock timeout value to 0 milliseconds:

LOCK_TIMEOUT(0);

In this example, the lock timeout value is set to 0 milliseconds for the current session. Any subsequent lock acquisition operations will not wait and will throw an exception immediately if the lock cannot be acquired.

Example 3 - Retrieving the current lock timeout value:

SELECT LOCK_TIMEOUT() AS current_timeout;

In this example, the current lock timeout value is retrieved using the LOCK_TIMEOUT function. The value will be returned as the result of the query.

There are no related functions specifically related to the LOCK_TIMEOUT function in H2 database.