View on GitHub

Application Locker

Provides file-based locking mechanism with inter-process communication support

Open library documentation Download this project as a .jar file Download this project as a Maven/Gradle dependency

AppLocker

Build Maven Central Javadoc

AppLocker is a small library which provides the often missing single instance functionality.

Features

Quick Start

AppLocker locker = AppLocker.create("my-app")
        .setMessageHandler(file -> open(file))  // optional: answer messages from other instances
        .build();

if (!locker.tryLock()) {
    // another instance is running: pass it the file and exit
    locker.sendMessage(file);
    System.exit(0);
}

AppLocker.Builder options, all optional:

I/O errors are reported as LockingException.

More details can be found in JavaDocs.

Download

Maven:

<dependency>
    <groupId>io.github.sanyarnd</groupId>
    <artifactId>app-locker</artifactId>
    <version>2.0.0</version>
</dependency>

Gradle:

implementation("io.github.sanyarnd:app-locker:2.0.0")

Jars are also available in GitHub Packages and on the releases page.

Building

Requires JDK 25:

./gradlew build
./gradlew spotlessApply

Releasing

Pushing a tag like 2.0.0 publishes to Maven Central and GitHub Packages, creates a GitHub release and updates the site.

Secrets: MAVEN_CENTRAL_USERNAME, MAVEN_CENTRAL_PASSWORD (Central Portal token), GPG_PRIVATE_KEY, GPG_KEY_PASSPHRASE.

Changelog

See CHANGELOG.md.