Quantcast
Channel: Active questions tagged redis+java - Stack Overflow
Viewing all articles
Browse latest Browse all 2204

Java spring distributed lock with redis: different lock timeout for each lock

$
0
0

I need to create locks for each task execution, however different tasks can have differents locks timeout. I'm using Spring distributed lock with Redis, there's a snippet of my example code:

@Overridepublic boolean lock(String taskKey) {    if(taskKey == null || taskKey.isEmpty()){        throw new IllegalArgumentException("Key must be not null!");    }    Lock lock = lockRegistry.obtain(taskKey);try{    if(!lock.tryLock()){        logger.warn("Unable to lock resource {}", taskKey);        return false;    }    logger.debug("Resource {} locked ", taskKey);    return true;}catch(Exception exc){    throw exc;}

}

and what I want is to set differents lock timeout for each taskKey. How can i do that?


Viewing all articles
Browse latest Browse all 2204

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>