BgeeDB / bgee_apps

Source code of the Java Bgee applications
https://bgee.org/
Creative Commons Zero v1.0 Universal
2 stars 1 forks source link

Stop storing one DAOManager per thread? #67

Open fbastian opened 4 years ago

fbastian commented 4 years ago

In GitLab by @fbastian on Oct 7, 2015, 24:07

Currently, calling DAOManager.getDAOManager() in a given thread always returns the same DAOManager instance (~ "per-thread singleton"). This was useful when we weren't using dependency injection everywhere, we could just call getDAOManager() from anywhere and be happy.

Now that we use dependency injection, DAOManager.getDAOManager() could always return a new instance; we would acquire it at the beginning of an operation (e.g., when calling FrontController.doRequest), and we would inject it everywhere, so that there shouldn't be more than one DAOManager used in a given thread (and so, no more than one connection to the database), if it is what we want.

Issue #58 describes a similar problem with BgeeProperties.

Also, should we keep storing DAOManagers associated to a given thread in a synchronized Map? This is notably used to allow to kill a connection from another thread (to interrupt a long-running query). But this feature of storing DAOManagers to be potentially interrupted could be implemented by another class, e.g., TaskManager.

But, it also allows to close all DAOManagers when calling DAOManager.closeAll() (useful, e.g, for a servlet shutdown listener). So, maybe we should keep storing all opened DAOManagers.

fbastian commented 4 years ago

In GitLab by @fbastian on Oct 7, 2015, 24:07

Title changed from Stop storing a DAOManager per thread? to Stop storing one DAOManager per thread?