Have you ever had to write a SINGLETON IN JAVA? They can be hard to get right - I had a few coding bugs while filming the video! There are also multiple different types between ENUM SINGLETONS, LAZY VS EAGER SINGLETONS, MULTI-THREADED DOUBLE CHECKED LOCKING SINGLETONS, the list goes on. Then there's the problem of preventing this design pattern from being broken, typically via REFLECTION. In this video, I'll go through the common cases for singletons and a few different sample implementations, going over the PROS AND CONS FOR DIFFERENT SINGLETONS.
In the end, you want to make sure that the singleton you're writing covers you for the cases you need to defend against, whether that's multi-threaded use, reflection, cloning, serialization, or other things. Hopefully this video gives you some ideas to ponder the next time you need to write a singleton!
I'm Will Tollefson, a guy who loves to NEVER STOP LEARNING and teach others what I've learned. If you're enjoying the content, please LIKE, SUBSCRIBE, and SHARE!
VIDEO CHAPTERS:
0:00 Introduction
0:40 Enum Singleton
2:10 Eager Singleton With Static Field
6:28 Lazy Singleton With Static Field
8:54 Synchronized Lazy Singleton
9:55 Double Checked Locking Singleton
12:52 Bill Pugh Singleton
Auf dieser Seite können Sie das Online-Video The Singleton Design Pattern In Java mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Will Tollefson 12 Januar 2024 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 3,768 Mal angesehen und es wurde von 124 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!