Package org.h2.store

# Class FileLock

java.lang.Object
org.h2.store.FileLock

All Implemented Interfaces:
  `Runnable`

public class FileLock extends Object implements Runnable
The file lock is used to lock a database so that only one process can write to it. It uses a cooperative locking protocol. Usually a .lock.db file is used, but locking by creating a socket is supported as well.

## Constructor Summary

Constructors
Constructor
Description
`FileLock(TraceSystem traceSystem, String fileName, int sleep)`
Create a new file locking object.

## Method Summary

Modifier and Type
Method
Description
`static FileLockMethod`
`getFileLockMethod(String method)`
Get the file locking method type given a method name.
`String`
`getUniqueId()`
`Properties`
`load()`
Load the properties file.
`void`
`lock(FileLockMethod fileLockMethod)`
Lock the file if possible.
`void`
`run()`
`Properties`
`save()`
Save the lock file.
`void`
`setProperty(String key, String value)`
Add or change a setting to the properties.
`void`
`unlock()`
Unlock the file.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### FileLock

public FileLock(TraceSystem traceSystem, String fileName, int sleep)
Create a new file locking object.

Parameters:
  `traceSystem` - the trace system to use
  `fileName` - the file name
  `sleep` - the number of milliseconds to sleep

## Method Details

### lock

public void lock(FileLockMethod fileLockMethod)
Lock the file if possible. A file may only be locked once.

Parameters:
  `fileLockMethod` - the file locking method to use
Throws:
  `DbException` - if locking was not successful

### unlock

public void unlock()
Unlock the file. The watchdog thread is stopped. This method does nothing if the file is already unlocked.

### setProperty

public void setProperty(String key, String value)
Add or change a setting to the properties. This call does not save the file.

Parameters:
  `key` - the key
  `value` - the value

### save

public Properties save()
Save the lock file.

Returns:
  the saved properties

### load

public Properties load()
Load the properties file.

Returns:
  the properties

### getFileLockMethod

public static FileLockMethod getFileLockMethod(String method)
Get the file locking method type given a method name.

Parameters:
  `method` - the method name
Returns:
  the method type
Throws:
  `DbException` - if the method name is unknown

### getUniqueId

public String getUniqueId()

### run

public void run()

Specified by:
  `run` in interface `Runnable`