开发者

Should I make my database adaptor class a singleton?

开发者 https://www.devze.com 2023-02-24 06:47 出处:网络
I am using the database adaptor from devx.com I was wondering if I should make it a singleton so I can 开发者_开发技巧easily use it from a number of different classes without having to worry about mu

I am using the database adaptor from devx.com

I was wondering if I should make it a singleton so I can 开发者_开发技巧easily use it from a number of different classes without having to worry about multiple instances?


Though your logic is valid, I dont think you should. Think of concurrencies, eg. class X is updating the database, and class Y is retreiving values from it at the same time . So you have 2 operations on the database at the same time; having a singleton shall prevent this, as the db connection needs to be closed/reopened .

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号