Bin: As far as i know the number of connections that are allowed simultaneously depends on your database, not on tomcat (unless you are using some default pool; which you say you aren't.) You could contact your database administrator to see what the limit is in your case. Unless you expect very heavy usage of your application, opening and closing a separate connection for each post or get (which is what will happen if you declare, open and close a connection within your doPost and doGet) will work fine.. The point is that decalring a connection object as an instance variable of your servlet will *not* work for simultaneous access. So just give it a shot: change your connection object decalaration to be inside your doPost/doGet, open it at the top of these methods and close it at the end. This essentially gives each user a connection object for his/her own. If this wont work for the number of people you expect to simultaneously us your application, you may not have a choice other than to use some kind of connection pooling mecahnism.
Good luck! Geeta bin cai wrote: > Could you tell me why closing connection within > doGet/doPost can be a solution. I used to do this way, > finally i thought it is unnessary so i took off. > besides, do you think my tomcat server has limit > amount of connections. i read from internet knowing > the default connections is 5 for free tomcat > application. I guess this could be reason. i am just > to find a way to change it. could you give me a hint. > Thanks a lot > bin > --- Geeta Ramani <[EMAIL PROTECTED]> wrote: > > If you want a quick and dirty solution, just declare > > (<--this is important!), > > initialise, and close your connection object within > > your doPost/doGet methods. > > You should be ok then. > > Geeta > > > > bin cai wrote: > > > > > Hi, Geeta and Frank, > > > Thanks you guys. Maybe i will think using > > connection > > > pool later. however my intership ends this month. > > > probably there is new intership student can do > > that. > > > before i leave, i really hope i will works. the > > test > > > will go tomorrow. so i think i have no time to > > switch > > > to connection pool option. I am trying to find way > > > around this problem. > > > do you think i should write function to close the > > > connection in my servlet application? > > > --- FRANK WELCH <[EMAIL PROTECTED]> wrote: > > > > I have had success using a global Connection > > > > Manager. > > > > > > > > See > > > > > > > > > > http://www.servlets.net/support/downloads/samplecode/dbpooling/index.html > > > > > > > > Frank > > > > > > > > ----- Original Message ----- > > > > From: "Geeta Ramani" <[EMAIL PROTECTED]> > > > > To: <[EMAIL PROTECTED]> > > > > Sent: Monday, August 12, 2002 3:53 PM > > > > Subject: Re: connection reset by peer, system > > slow > > > > down > > > > > > > > > > > > > Hi there: i think your problem is right there: > > you > > > > should not define your > > > > > connection object as an instance vaiable. > > Since > > > > servlets are not > > > > inherantly > > > > > thread safe, this means that if multiple users > > > > access your servlet > > > > > simultaneously, you will run into trouble > > (unless > > > > you synchronize access > > > > to the > > > > > connection object). You can test this theory > > out > > > > by declaring and > > > > initialising > > > > > your connection in the doGet/dopost methods. > > You > > > > will not then have > > > > problems > > > > > with simultaneous access.. Of course the best > > > > soultion is to declare a > > > > > connection pool as an instance variable in > > your > > > > servlet, initialise it in > > > > the > > > > > init method and then pick up connections and > > > > release them as you need them > > > > > within your doGet/doPost methods. > > > > > > > > > > Hope this helps, > > > > > Geeta > > > > > > > > > > bin cai wrote: > > > > > > > > > > > Hi, Samuel, > > > > > > thanks first. > > > > > > I define connection as instance variable and > > > > create > > > > > > connection in the init method like: > > > > > > > > > > > > public synchronized void init (ServletConfig > > > > config) > > > > > > throws ServletException { > > > > > > try { > > > > > > super.init(); > > > > > > } catch(Exception ex) { > > > > > > > > System.out.println(ex.getMessage()); > > > > > > } > > > > > > > > > > > > // establish connection > > > > > > try{ > > > > > > conn = getConnected(); > > > > > > } catch(Exception ex) { > > > > > > > > System.out.println(ex.getMessage()); > > > > > > > > > > > > as i know the connection will closed > > > > automatically > > > > > > when servlet is unload or stoped. so in my > > > > application > > > > > > i didn't close connection just close > > statment > > > > created > > > > > > by connection. is this the problem? > > > > > > and where i can check how many process in > > mysql? > > > > > > Very appreciate your help. > > > > > > --- Samuel Chen <[EMAIL PROTECTED]> wrote: > > > > > > > You might check out how many mysql > > processes > > > > are > > > > > > > running. > > > > > > > If you did not close the database > > connections > > > > > > > properly, > > > > > > > mysql will have to open too many > > connections > > > > and > > > > > > > eventually > > > > > > > everything will be slowed down, even your > > > > servlet > > > > > > > engine can be crashed. > > > > > > > > > > > > > > Sam. > > > > > > > -------------------------------------- > > > > > > > Need a Bug Tracking System? > > > > > > > Try http://www.websina.com/bugzero/ > > > > > > > -------------------------------------- > > > > > > > > > > > > > > > > > > > > > > > > > > > > ----- Original Message ----- > > > > > > > From: "bin cai" <[EMAIL PROTECTED]> > > > > > > > To: <[EMAIL PROTECTED]> > > > > > > > Sent: Monday, August 12, 2002 8:58 AM > > > > > > > Subject: connection reset by peer, system > > slow > > > > down > > > > > > > > > > > > > > > > > > > > > > Hello, > > > > > > > > I got one serious problem. any help will > > be > > > > > > > > appreciated very much. Thanks in > > advance. > > > > > > > > my project is about online exam. > > students > > > > take > > > > > > > exam > > > > > > > > through internet.This sytem is developed > > by > > > > java > > > > > > > > servlet, html, mysql and tomcat 3.2.3. > > Last > > > > Friday > > > > > > > we > > > > > > > > have a test on my system. some students > > took > > > > the > > > > > > > exam > > > > > > > > for half hour. > > > > > > > > It seemed ok. after exam, we (3 guys) > > had a > > > > > > > further > > > > > > > > tesing on my system. we try to log to > > system > > > > using > > > > > > > > different login ids at the same machine. > > or > > > > using > > > > > > > same > > > > > > > > loin id to log to sytem at different > > > > machines. but > > > > > > > the > > > > > > > > sytem suddenly slow down. very slow. > > when i > > > > check > > > > > > > the > > > > > > > > server, find the waning message like > > "socket > > > > > > > > exception....connection reset by peer. > > > > > > > > I read some documentation about this > > error. > > > > i was > > > > > > > > informed that the message will happen > > when > > > > client > > > > > > > send > > > > > > > > another request before the previous > > request > > > > is > > > > > > > > returned. it will not hurt the > > performance. > > > > but in > > > > > > > my > > > === message truncated === > > ______________________________________________________________________ > Post your ad for free now! http://personals.yahoo.ca > > ___________________________________________________________________________ > To unsubscribe, send email to [EMAIL PROTECTED] and include in the body > of the message "signoff SERVLET-INTEREST". > > Archives: http://archives.java.sun.com/archives/servlet-interest.html > Resources: http://java.sun.com/products/servlet/external-resources.html > LISTSERV Help: http://www.lsoft.com/manuals/user/user.html ___________________________________________________________________________ To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff SERVLET-INTEREST". Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
