Distributed Concurrency Control

前端 未结 13 1726
栀梦
栀梦 2021-01-29 20:35

I\'ve been working on this for a few days now, and I\'ve found several solutions but none of them incredibly simple or lightweight. The problem is basically this: We have a cl

13条回答
  •  悲哀的现实
    2021-01-29 21:20

    Since you are already connecting to a database, before adding another infra piece, take a look at JdbcSemaphore, it is simple to use:

    JdbcSemaphore semaphore = new JdbcSemaphore(ds, semName, maxReservations);
    boolean acq = semaphore.acquire(acquire, 1, TimeUnit.MINUTES);
    if (acq) {
     // do stuff
     semaphore.release();
    } else {
      throw new TimeoutException();
    }
    

    It is part of spf4j library.

提交回复
热议问题