|
The DAO thing is definitely a good idea, but not so much because of thread-safety. Its main benefit is that you can close your database connections (i.e. return them to the connection pool) faster and more reliably. Database connections are a scarce resource. So yes, you should use them. But your servlet still isn't thread-safe. You have a lot of instance variables (and static variables too) such as "dsname" which are shared between all users of the servlet. They aren't necessarily thread-safe. It looks to me as if some of them are set up in the init() method, so they are essentially constants. Those aren't a problem. But others like "dmd" are set up anew for each query, so they are a problem. If you can make them local variables in the method where they are used, that would be the best. Or if they are used in several methods, then pass the data around as parameters to those methods. Regards PC2 -----Original Message----- From: java400-l-bounces@xxxxxxxxxxxx [mailto:java400-l-bounces@xxxxxxxxxxxx] On Behalf Of RPower@xxxxxxxxxx Sent: May 4, 2006 10:18 To: Java Programming on and around the iSeries / AS400 Subject: Re: Connection Pooling Ok, I've done some reading and stuff on how to handle database records and I think I got it now, but I want someone to verify my thoughts. Instead of accessing my result sets and record processing through the servlets, because they are multithreaded, I'm better off creating a DAO class for each table and using instantiated classes of that because instantiated classes are thread safe yes? My code follows for a simple servlet that saves a new softwareName. Thus I shouldn't get two different threads changing the variables in each one as it goes thru. Thanks,
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.