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
En esta página del sitio puede ver el video en línea The Singleton Design Pattern In Java de Duración hora minuto segunda en buena calidad , que subió el usuario Will Tollefson 12 enero 2024, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 3,768 veces y le gustó 124 a los espectadores. Disfruta viendo!