When programming there are decisions to make all the time, like:
(I hope that question is not too common:)
What should your DB do and what excercises are better done by your Java-code, regarding performance issues in web applications.
Maybe differing between small and huge projects is reasonable
Extending Ignacio's answer a bit: the DB typically has a big latency (unless it is physically on the same machine), so you want to hit it as rarely as possible. If you use an ORM like Hibernate, you get caching and lazy loading for free; otherwise you need to take care of these yourself.
Thus it is OK to fetch GUI element data from the DB once - then cache and reuse it locally. And it is better to count entries of a list locally if you already have all the elements. If you need a query anyway, you can try combining the fetches into one. However, if you have a huge list and you want to select relatively few elements from it, it may be preferred to let the DB do the work and return only the selected entries, as opposed to cramming a large amount of data through a slow network connection.
Database is slow. Java code is relatively very fast. Cache everything pulled from the database in memory if possible, possibly using something like memcache (if relevant; I don't do much Java web code).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With