Timestamps 00:01 - Ways to break the singleton pattern 01:14 - There are multiple ways to break the singleton pattern 02:32 - Constructor in Singleton pattern 04:09 - There are two ways to avoid breaking the singleton pattern 06:19 - Two ways to break singleton pattern 09:15 - The solution to the problem is to overwrite the resolve method using Red Resolve technique. 12:52 - The method explained in the video helps in breaking the singleton pattern. 15:20 - Ways to break singleton pattern
@utkarshrazzz9964 Жыл бұрын
Appreciable sir, waiting eagerly for your next videos on this series.
@sgsenginier3 ай бұрын
Awesome🙂Thanks.🙏
@nikkm20009 ай бұрын
small query- at 6:12 min---I have done below---two different instance created..... Constructor constructor = Samosa.class.getDeclaredConstructor(); constructor.setAccessible(true); Samosa s1= constructor.newInstance(); System.out.println(s1.hashCode()); Samosa s2= constructor.newInstance(); System.out.println(s2.hashCode());
@skaftab39547 ай бұрын
try this method: public class Samosa{ private static Samosa samosa; private static boolean objCreated=false; private Samosa() throws Exception { if (objCreated) { throw new Exception("One object already exists, you cannot call the constructor one more time"); } objCreated=true; }
@preranagayke1464 Жыл бұрын
Hands of to your efforts
@himanshubaviskar39664 ай бұрын
Good Explanation 😊
@vaibhavkalyankar86504 ай бұрын
lol sir😃 @4:27 Ho gaya kaam tamam singleton ka 🤪 Nice sir
@sumitsaini-lo8ic8 ай бұрын
Hi Durgesh, are you sure that if you are checking for null condition in the private constructor to prevent breaking the singleton pattern it will prevent breaking the singleton pattern?
@spider80156 ай бұрын
alag level sir aapka
@azaankhan03116 ай бұрын
outstanding👍❤
@ravijaiswal92317 ай бұрын
Samosha Khane ka man kar diya @Durgesh Bhaiya, raat hai milega bhi nahi🤤
@subhamgoswami8607 Жыл бұрын
readResolve par detail video chaiye sir plz
@ketank6864 Жыл бұрын
Thank you for awesome playlists
@rohitjaiswal9468 ай бұрын
Thanks for the great video, but I have one question, we are able to create multiple instances using reflection API even after adding the throwing exception in the constructor level. MyLazySingletonUnBreakable unBreakable2 = constructor.newInstance(); System.out.println(unBreakable2.hashCode()); //Here we are able to create another object MyLazySingletonUnBreakable unBreakable3 = constructor.newInstance(); System.out.println(unBreakable3.hashCode());
@skaftab39547 ай бұрын
hi, i got solution to your problem you have to add one more static boolean variable, here it goes: public class Student { private static Student stud; private static boolean objCreated=false; private Student() throws Exception { if (objCreated) { throw new Exception("One object already exists, you cannot call the constructor one more time"); } objCreated=true;// it will be true when constructor created for the first time so from next time the constructor is called it will give exception }
@MadhuKinneraDev Жыл бұрын
Great video sir.
@SaasBahuCares Жыл бұрын
A video on java-17 features pls ❤
@poorpanda903310 ай бұрын
Thanks a lot
@qurashishebi7988 Жыл бұрын
keep it up
@varnitajaiswal8569 Жыл бұрын
nice video sir
@RishiRajxtrim8 ай бұрын
great
@rohandahiya6268 Жыл бұрын
What is double check locking and how is it better that single check locking ?
@UmeshMane-k7d10 ай бұрын
Hi Sir, In Singleton design pattern could you please explan why we need to use "volatile" concept.
@suar_pilla9 ай бұрын
bihari nehi janta
@mishra.pritam2 ай бұрын
so that al threads know the current value of samosa if made volatile
@monasoni48818 ай бұрын
good
@krishasharma_AJ Жыл бұрын
Why we are using null check 2 times in get samosa method ?
@NidhiSharma-sw4oz11 ай бұрын
imagine both the threads are currently inside the 1st null condition. as soon as synchronised is there, thread t2 waits and t1 makes an object. now t1 has successfully made the object and come out of synchronised block. now t2 will go inside synchronised block. It would have tried to create another object BUT IT WAS NOT ABLE TO MAKE ANOTHER OBJECT BECAUSE OF 2ND NULL CHECK!!.
@gamerauto9 ай бұрын
@@NidhiSharma-sw4oz Wow Nidhi you're so smart, mamma would be so proud of you!
@vinaychauhan76279 ай бұрын
Why dont we start our synchronized block from the first if condition.
@GeneralistDev Жыл бұрын
What is the extension name which maek comments fire and terminal icons
@sandeepkumar-eq8nn Жыл бұрын
Marunga mein he aur bachaunga bhi mein he
@kuldeepvm9 ай бұрын
You forgot to mention where that readResolve method is coming from.
@nsudhir_here6 ай бұрын
I am not a java person but I can guess that it comes from serializable interface.
@kuldeepvm6 ай бұрын
@@nsudhir_here nope. It's a marker interface.
@siddharthdandamudi69494 ай бұрын
second point of Deserilization was confusing could have explained it better.
@sagardarade8 ай бұрын
With Deserialization Serialzation you did not explain how it's breaking singleton pattern.