Singleton Design Pattern || Implementation with Eager & Lazy Loading ✌🏻

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 พ.ย. 2024

ความคิดเห็น • 12

  • @dushyantsingh5299
    @dushyantsingh5299 ปีที่แล้ว +1

    Very knowledgeable lecture. Thank u so much.

  • @vipulkumar3329
    @vipulkumar3329 ปีที่แล้ว +1

    Thank you for sharing this concept video, it’s so important you made it easy to understand 😊

  • @ashmitachauhan7
    @ashmitachauhan7 ปีที่แล้ว +1

    Very important concept😍❤
    Thank you🙏

  • @rafi2713
    @rafi2713 6 หลายเดือนก่อน

    There are two null checks inside the getInstance() method because it is possible for the instance variable to be null even after the synchronized block.
    This can happen if two threads enter the synchronized block at the same time. The first thread will check if the instance variable is null, and if it is, it will create a new instance of the Singleton class. However, before the first thread can assign the new instance to the instance variable, the second thread may also enter the synchronized block and check if the instance variable is null. If it is, the second thread will also create a new instance of the Singleton class.
    This would result in two instances of the Singleton class being created, which is not desired.

  • @manshalkhatri9289
    @manshalkhatri9289 ปีที่แล้ว +1

    Does that mean that we reduce the 4 lines each time when we use a lazy block

    • @NativeMobileBits
      @NativeMobileBits  ปีที่แล้ว +1

      as its singleton, this is mix of synchronization and lazy loading, I explained how its lazy loading where we make object on first call of getInstance()

  • @freesources6872
    @freesources6872 ปีที่แล้ว

    is that double null check important?

    • @NativeMobileBits
      @NativeMobileBits  ปีที่แล้ว

      Yes check the full explanation in video for why