I just read this question and the answer claims:
"Lets assume db connection object is singleton in my application"
This is a must not. Your database connection MUST NEVER BE (yes, bolded and with capitals to make sure you and every reader never make this mistake) a singleton object. Your Connection con MUST NOT be part of a singleton to keep it open all the time. Instead, use a proper database connection pool that will take care of opening the necessary physical database connections and keep them alive through the live of your application.
We of course use a connection pool to take care of our, well, connections. Still, we store this pool in a singleton. How else would one ensure that it lives throughout the application? Ist his bad practice?
Aucun commentaire:
Enregistrer un commentaire