watch this. please dont take it as it is. just take it as a scenerio.
i have some handler classes which is instantiated inside init() of
servlet. in the constructor of every handler class i m constructing my DB classes say DAOs.
1.
now if i get the connection object, from DriverManager.getConnection(), in the constructor of my each DAO. and all the methods inside that particular DAO use the same connection object to query or update the DB. then if i write
synchronized(conn){
....
...
int n = conn.executeUpdate();
}
then it will be threadsafe. means no other
thread can execute an update on that particular table using the same method. right.
2.
if i get the connection object inside every method. then it would not be like that. right.
anybody here can help me out by coming up with some better idea in terms of performance. any comments would be appreciated. because i think if it is right then it would result in lack of performance. isn't it.