Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

is using a static data source ok?

 
Joe Pit
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's wrong with doing the lookup for every request?
 
Joe Pit
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm assuming doing the lookup every request adds to the processing time / response time of the request
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats true. Depends on the application I guess. One millisecond may not be much in one, but a lot in another.
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic