One DAO per stream or thread safe DAO?

I am wondering if there is an approved practice in a multi-threaded application. Should I have one DAO per thread or just make one DAO thread safe singleton.

+5
source share
2 answers

It really depends a lot on the mechanism you use to access the data. If you have very scalable access to data and many threads, using some form of static access to the data of the stream can be beneficial.

If you do not have scalable data access, your provider does not support multiple threads for each process, or you just do not need scalability at this moment, using a singlet with the appropriate synchronization is simpler and easier to implement.

For most business-style applications, I personally find that a singleton approach is easier to maintain, and probably better - if not for any other reason, but much simpler, much easier to test effectively. Having multiple threads for accessing data is probably not required, since accessing data is probably not a bottleneck that affects usability (if you design batch requests correctly as well).

+4
source

, , :

1) , .

2) , Active Record pattern. ( DAO, -, .)

0

All Articles