I’m wondering if there’s an approved practice in a multi-threaded app. Should I have one DAO per thread or simply make one DAO a thread safe singleton.
I’m wondering if there’s an approved practice in a multi-threaded app. Should I have
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This really depends a lot on the mechanism you’re using for data access. If you have a very scalable data access, and lots of threads, using some form of thread static data access can be advantageous.
If you don’t have scalable data access, your provider doesn’t support multiple threads per process, or you just don’t need the scalability at that point, using a singleton with appropriate synchronization is simpler and easier to implement.
For most business style applications, I personally think the singleton approach is easier to maintain, and probably better – if for no other reason than it’s much, much easier to test effectively. Having multiple threads for data access is likely not required, as the data access is probably not going to be a bottleneck that effects usability (if you design correctly, and batch requests appropriately).