| Author |
is using a static data source ok?
|
Joe Pit
Greenhorn
Joined: Jan 21, 2011
Posts: 5
|
|
I made the data source static so that i wont need to do the lookup every time a request comes into my webapp and i was wondering if it would cause problems. The code checks if its null, and if it is, makes it. Two threads could make it, and I guess one would be overwritten, because its not technically a singleton, but i dont think that would cause problems, would it? Here's the code
edit: Also, multiple webapps will be using the same dataSources. The dataSources are in my jetty.xml file.
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
|
What's wrong with doing the lookup for every request?
|
 |
Joe Pit
Greenhorn
Joined: Jan 21, 2011
Posts: 5
|
|
|
I'm assuming doing the lookup every request adds to the processing time / response time of the request
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
|
That's premature optimization. No doubt it does increase the processing time. But by how much? Let's suppose you could save 1 millisecond per request by caching the DataSource. Would you do that? I wouldn't, because then I would have to spend my programming time asking questions such as the one you're asking here.
|
 |
Joe Pit
Greenhorn
Joined: Jan 21, 2011
Posts: 5
|
|
|
Thats true. Depends on the application I guess. One millisecond may not be much in one, but a lot in another.
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
One millisecond isn't much in a web application. But remember, I just pulled that number out of my back pocket. I have no idea what the real number is. It's my sorta-educated guess that the number is small, but that's just a guess. I would say there are better places than this question to look for speedups in a web application, but again that's just a guess with respect to your application.
|
 |
 |
|
|
subject: is using a static data source ok?
|
|
|