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?