----- Original Message ----- From: "bin cai" <[EMAIL PROTECTED]> To: "mysql list" <[EMAIL PROTECTED]> Sent: Friday, May 17, 2002 10:59 AM Subject: set connection as instance variable ( servlet and mysql)
> Hi, > My application is about online exam with java servlet > as tool, tomcat 3.2.3 as server solution , mysql 3.49 > as the backend. > considering 180 students take the exam at same time > within 50 minutes, there are a lot of transactions > with database. > what i did right now is to define connection in local > variable(within doGet or doPost method), every time > this servlet is called, new connection is created. > after transaction is done, this connection is closed. > I am worrying the speed.(it will comsume a lot > connection and time for open new connection). > > so I am thinking to define connection as instance > variable in every servlet, so it can save sometime to > open new connection. However, I am not sure if it will > cause multi-thread problem? How and when i can close > the connection. You should definitely use a connection pool. Sharing an instance of a connection will work, but you will have performance problems, and it is impossible to demarcate transactions when you do this. If you upgrade to Tomcat-4, it has connection pooling built in. Otherwise you might want to take a look at the commons project at http://cvs.apache.org/viewcvs/jakarta-commons/dbcp/ -Mark --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php