Example usage for io.vertx.core.shareddata SharedData getLock

List of usage examples for io.vertx.core.shareddata SharedData getLock

Introduction

In this page you can find the example usage for io.vertx.core.shareddata SharedData getLock.

Prototype

void getLock(String name, Handler<AsyncResult<Lock>> resultHandler);

Source Link

Document

Get an asynchronous lock with the specified name.

Usage

From source file:examples.SharedDataExamples.java

License:Open Source License

public void example5(Vertx vertx, SharedData sd) {
    sd.getLock("mylock", res -> {
        if (res.succeeded()) {
            // Got the lock!
            Lock lock = res.result();

            // 5 seconds later we release the lock so someone else can get it

            vertx.setTimer(5000, tid -> lock.release());

        } else {/*from  w  w  w  .j  a v a 2 s  .  c  o m*/
            // Something went wrong
        }
    });
}