This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi all, in my application i have two databases. lets call them a & b.from database a i will be just reading data and displaying it to the user using a sevlet.no writing has to be done.but on database b i have to perform writing as well as reading operations.since multiple users will be accessing this database i have a few questions i) how do i take care of the cuncurrency issue? ii)will the cuncurrency issue come in only when two users try to write something to the database at the same time or is it a problem even when multiple users try to read at the same time? iii) should i implement connection pooling?i dont expect a lot of cuncurrent users(around 50 or so).is there any threshold value for the no. of concurrent users beyond which it is advisable to implement connection pooling. Thanks in advance. Subbu
Hi Subbu, Typically your db will take care of concurrent writes at a file level. This is unlikely to be a problem for you unless users regularly overwrite the same piece of data. The database is a bit of a black box this way unless you're doing something pretty demanding with it. Database access with multiple users is easy to get wrong with servlets (I fell into every trap :-). DO implement connection pooling -> Marty Hall (from Sun) does a good one available at http://www.coreservlets.com/. Watch out, though, it doesn't handle reconnection to the database if your db goes down very well. Watch out for synchronizing your database access methods, too. Also use a servlet engine that runs multiple threads for each servlet so that access to that servlet does not stop as all the users queue up around that one db access method (or use SingleThreadModel (but remember, it's expensive ito resources)). Or you can just ignore all of this tiresome stuff and borrow someone else's and use Resin from www.caucho.com. They do a good connection pool all for you. Cheers, Rob