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.
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.
Joined: Jan 21, 2011
Thats true. Depends on the application I guess. One millisecond may not be much in one, but a lot in another.
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.