Using Static methods or none static methods in Dao Class?

前端 未结 5 1508
庸人自扰
庸人自扰 2020-12-30 06:22

Hi I generate Dao classes for some DB operations

in this manner making methods of Dao class as static or none static is better?

Using sample dao class belo

5条回答
  •  孤独总比滥情好
    2020-12-30 06:55

    this code is not thread-safe the way you have it written.

    if you have the dataAccessor field and the methods static like this, you will have concurrency problems with multiple clients hitting this code at the same time. it's likely you'll have very strange exceptions occuring, and even possible that one client could see another client's data.

    get rid of static on these methods and this field and instantiate a new instance of SampleDao for each client.

提交回复
热议问题