Giter VIP home page Giter VIP logo

Comments (6)

mrniko avatar mrniko commented on May 20, 2024

Please share the code to reproduce the issue.

from redisson.

mrniko avatar mrniko commented on May 20, 2024

Make sure that the lock wasn't unlocked by the time when the second thread acquired it.

from redisson.

OuDale avatar OuDale commented on May 20, 2024

Make sure that the lock wasn't unlocked by the time when the second thread acquired it.

Thanks reply,

  1. the log shows that the two threads acquired the lock in a very short period of time. I don't think it is the case of releasing and acquiring the lock again.
  2. I didn't assigned a leaseTime and unlocked in finally body.
private void generate() {
        RLock lock = redisson.getLock(key);
        try {
            String threadName = Thread.currentThread().getName();
            boolean locked = lock.tryLock();
            if (locked && shouldGenerateTask() {
                log.info("locked by key:{} with thread:{}", key, threadName);
                saveTask();
            }
        } catch (Exception e) {
            Thread.currentThread().interrupt();
        } finally {
            if (lock.isHeldByCurrentThread()) {
                lock.unlock();
            }
        }
    }
2024-01-12T12:00:07.514288425Z 2024-01-12 12:00:07.514 INFO 7 --- [ XNIO-1 task-4] .s.p.a.t.c.h.i.test : locked by key:App:Procurement:PENDING_PRICING:1400_65_2 with thread:XNIO-1 task-4

2024-01-12T12:00:07.542088285Z 2024-01-12 12:00:07.541 INFO 7 --- [ XNIO-1 task-2] .s.p.a.t.c.h.i.test : locked by key:App:Procurement:PENDING_PRICING:1400_65_2 with thread:XNIO-1 task-2

from redisson.

OuDale avatar OuDale commented on May 20, 2024

This is occurring in a concurrent scenario where the real situation involves listening to a database change data capture (CDC). Then, two threads simultaneously acquire the lock and save two separate task data.

from redisson.

mrniko avatar mrniko commented on May 20, 2024

Can you add log.info("unlocked1 by key:{} with thread:{}", key, threadName); after if (lock.isHeldByCurrentThread()) {

add log.info("unlocked2 by key:{} with thread:{}", key, threadName); after lock.unlock();

from redisson.

OuDale avatar OuDale commented on May 20, 2024

thanks for your help

from redisson.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.