Hashtable vs Direct database access in JSP Pages
2 posts in topic
Flat View  Flat View

Posted By:   Amit_Kirdatt
Posted On:   Monday, March 26, 2001 12:15 PM

In a web application is Hashtable access faster or better than database access? Some developers I work with are arguing that the hashtables are faster when compared to getting data directly from the database. The size of the database is 3mb right now.
If the hashtables do give a faster access time, is there any reason we should or shouldn't use them?

Re: Hashtable vs Direct database access in JSP Pages

Posted By:   Luigi_Viggiano  
Posted On:   Tuesday, March 27, 2001 11:30 PM

Hashtable (or Maps) is faster than a database access. Sometimes it's better to use hastable instead of db, sometimes not: it depends on what you have to do with the data.

Hashtable (and Maps) is faster than a database because the data are already loaded in memory, and generally in a way to get it as faster as possible (hash functions etc.). When getting data from the db, commonly you are passing thru a network connection, then to a file system, and at last to (flat)memory.

Disadvantages of maps are that them charge lot of memory (more than just data size): you cannot use map with huge structures if you don't want to keep it all in memory.
Databases let you to keep in memory only a subset of the entire application data. Furthermore, Hashtables (and Maps) don't provide a persistent storage: when you turn off the machine all the data are lost!

Hashtable are not transactional, Hashtable are not relational, don't provide any data-constraints... in short, Hashtables and Maps are different from databases.

For keeping temporary data in an application and for keeping fast access data, Maps (and Hashtables) are the right choice.

For keeping businness/persistent/structured data, databases are right!

Maps are right for keep application configuration (Properties), for keeping little tables (like a subset cities, states, etc.) that are used very frequently and changed rarely. And so on...

Take in mind that with Java 2 it's preferable to use HashMap (or Map's sub-classes) instead of Hashtable. This is because of design changes in Java collection framework.

Re: Hashtable vs Direct database access in JSP Pages

Posted By:   Jerome_Munchenberg  
Posted On:   Monday, March 26, 2001 09:24 PM

Naturally a hashtable will provide much faster access than a database query! This should be quite obvious!

The only negative about using a hashtable of cached database content is the issue of concurrency. ie it is quite possible for the database to be updated, hence the hastable contents are no longer current.

About | Sitemap | Contact