One DAO per thread or threadsafe DAO?

后端 未结 2 1036
南旧
南旧 2021-02-10 04:27

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.

2条回答
  •  轮回少年
    2021-02-10 04:31

    Use the approach that best suits your application architecture, unless:

    1) Your data access objects are expensive to create, in which case you should lean toward a thread-safe singleton.

    2) Your objects maintain mutable state, as in the Active Record pattern. (Immutable DAO configuration state, like timeout thresholds, doesn't count.)

提交回复
热议问题