ReadWriteLock vs ReentrantLock

Поділитися
Вставка
  • Опубліковано 24 жов 2024

КОМЕНТАРІ • 52

  • @karthikrangaraju9421
    @karthikrangaraju9421 4 роки тому +14

    I like the way you visualize every concept! A picture speaks a thousand words. I'm looking forward to Basic Java interview videos, more distributed systems videos, Apache tomcat architecture, spring boot and spring basic intros!!!

  • @饶泽海
    @饶泽海 4 роки тому +8

    You are a talented teacher - thank you very much!

  • @naveensharma9834
    @naveensharma9834 5 років тому +5

    Nice information, good to know being a java developer. Though I want to ask how these locks will behave when its multi server application. I meant when book seat requests can go on any server. Lets say (R - Request , S - Server)
    R1 -> S1
    R2-> S2
    R3-> S3
    so on (All are writer threads)
    And all these server will access same db/seatchart.

    • @DefogTech
      @DefogTech  5 років тому +5

      Good question. Java locks cannot help with that use-case. We will need to use DB locks or some kind of distributed locks like from Redis

  • @RohitKumar-hx9ur
    @RohitKumar-hx9ur 4 роки тому

    one of the best stuff found till date. gone through all concurrency videos it is awesome. suggest u to create same in other topics like JVM , OOPS , EXCEPTION HANDLING in real-time.

  • @hyperborean72
    @hyperborean72 3 роки тому

    (almost) crystal clear explanation of the differences

  • @mahendharb5303
    @mahendharb5303 6 років тому +3

    Great channel I'm sharing this channel to my colleagues also

    • @DefogTech
      @DefogTech  6 років тому

      Thank you for the support!

  • @marcinkurek2950
    @marcinkurek2950 4 роки тому +4

    Very informative, thank You!

  • @vhxhao
    @vhxhao 3 роки тому

    Nice and simple explanation!

  • @atmiksoni5859
    @atmiksoni5859 5 років тому +1

    Please preparte video on transacation and propagation and also some algorithm

  • @hyperborean72
    @hyperborean72 4 роки тому +2

    @6:20 why do you call readResource/writeResource on an instance of the class? why not to make those methods static?
    in case of ReentrantLock you had that method static

  • @sharanyarai378
    @sharanyarai378 5 років тому +4

    Please clarify why would i need read lock or any lock when i am not going to change the state of object/shared resource?

    • @DefogTech
      @DefogTech  5 років тому +7

      If other thread is modifying the state, the thread reading the state can get incorrect value / partial value (not stale value) because writing a field is not atomic operation. This even for reading a read lock it's required

  • @vbar-ukr
    @vbar-ukr 3 роки тому

    Awesome explanation!

  • @sagarshekhar6296
    @sagarshekhar6296 6 років тому +2

    As per the video, it is clear that in ReadWrite Lock, one or more threads can read simultaneously and only one thread can write at a time.
    My concern is, why is it said to be ReentrantReadWriteLock instead of simply ReadWrite Lock.?

    • @DefogTech
      @DefogTech  6 років тому +3

      Because same as Reentrant lock with this lock also, the thread can re-enter the block when it already owns the lock

  • @shivendratiwari3238
    @shivendratiwari3238 2 роки тому

    Please make a video on Object and Class Level Locking

  • @NexusWorldPulse
    @NexusWorldPulse 5 років тому

    Superb and Informative ....thank you !!!

  • @protyaybanerjee5051
    @protyaybanerjee5051 3 роки тому

    So, in the code path, that allows to read state, why would I need to have LOCKS in there ? That's an overhead. Can you explain with an example ?

  • @hyperborean72
    @hyperborean72 4 роки тому

    can you please explain why Reentrant Lock does work only when all the thread write to the same resource?
    Is this the condition - they all have to write? or the condition - they all have to do the same operation (it can be read as well)?

  • @dowlathbashag65
    @dowlathbashag65 5 років тому

    Hi , I have an query about ReadWriteLock, this lock implemented internally for ConcurrentHashMap. Please let me know which lock mechanism used internally for ConcurrentHashMap is it Reentrant or ReadWriteLock...?

  • @azeemmohammed6284
    @azeemmohammed6284 5 років тому

    Can u explain event driven with debezium and push the changes to elastic search

  • @aneksingh4496
    @aneksingh4496 4 роки тому

    Can u please make a video on Stamped Lock

  • @praddybishti
    @praddybishti 5 років тому

    awesome video . Just one question , how can we achieve multiple reads and 1 write simultaneously ?
    I mean if its not possible with readWrite lock , then do we have any other way/concept through which we can acheive this .
    Thanks.
    Btw your videos makes lot of sense to me.

    • @DefogTech
      @DefogTech  5 років тому +1

      Reading and writing simultaneously is not possible, I mean to get correct results and maintain data integrity you have to do one thing at a time

  • @_abhishekmj_
    @_abhishekmj_ 3 роки тому

    How do they do in BookMyShow ? We can both read and update at same time ..

  • @av98
    @av98 3 роки тому

    Sir, come back.

  • @maybeyesterday
    @maybeyesterday 2 роки тому

    shouldnt the locks be static, am i wrong?

  • @AmanGarg95
    @AmanGarg95 6 років тому +1

    Thank you. Helpful.

    • @DefogTech
      @DefogTech  6 років тому

      You're welcome! Happy it helped

  • @kripamishra8147
    @kripamishra8147 5 років тому

    At time 8:25...we are having a thread2 which is reading a resource r1 and thread4 which is writing resource r1..
    is there any chance that thread 5 which wants to read r1 can read different values..
    so thread4 modified r1 with value 5, while thread2 still has value 4..then what value thread5 will be reading (4 or 5)..

    • @DefogTech
      @DefogTech  5 років тому

      thread 2 and thread 4 both want to read r1, thus are allowed to acquire read lock simultaneously.
      After this, thread 3 will be allowed to write to r1
      then thread 5 will be allowed to read r1, which will get the latest value (written by thread 3)... while thread 2 and 4 will read the value before thread 3.
      due to java memory model, thread will always read the latest value of r1 after acquiring the lock

  • @debbh274
    @debbh274 3 роки тому

    Fantastic

  • @TheGurukrushna
    @TheGurukrushna 3 роки тому

    Kudos

  • @Sobioytccc
    @Sobioytccc 5 років тому

    which book have you use to study concurrency .

    • @DefogTech
      @DefogTech  5 років тому

      Concurrency in practice by Brian Goetz

    • @Sobioytccc
      @Sobioytccc 5 років тому

      Thank you dear

    • @mr.bikashdeka7117
      @mr.bikashdeka7117 4 роки тому

      @@DefogTech That is old version. Do we have any latest version of Concurrency in practice by Brian Goetz

  • @shiyuwang
    @shiyuwang 4 роки тому

    awesome!

  • @vipinkoul9129
    @vipinkoul9129 4 роки тому

    Awesome :-) do you teach by any chance , pls let me know. Can i get in touch with you?

    • @DefogTech
      @DefogTech  4 роки тому

      hey Vipin.. no I don't do courses yet. only UA-cam videos once in a while

    • @vipinkoul9129
      @vipinkoul9129 4 роки тому

      @@DefogTech Awesome course, shows your level of knowledge :-)

  • @AleksandarT10
    @AleksandarT10 4 роки тому

    Make some more great videos!

  • @9939364566
    @9939364566 2 роки тому

    but why readLock is even created? I mean, if multiple threads can access the lock, then why have it in first place?

    • @DefogTech
      @DefogTech  2 роки тому +1

      As per Java memory model, if you dont access objects through locks, you can get stale value from cache, so its important in multi-threading to use locks even for reads.

  • @devanampriya1791
    @devanampriya1791 Рік тому

    god of concurrency