How to create mail session pool using java mail. I am using tomcat 5.5.
I tried several code about how to configure but nothing worked.
When I use it without JNDI entry means I created a new session every time I want to send mail
it worked fine.
Thank you William. Actually I am developing a web application using Tomcat 5.5.
And I come to know that the session object creation is an overhead to the server as in the case of database connection.
Specially when I expect thousands of users want mail session very frequently I must implement some mail session pool.
Yes session can be reused but if there are thousands of concurrent requests for one mail session object,
I doubt the situation may go out of control. That is why I am thinking to create a session pool.
Could you please tell me if it would create a critical situation when thousands of users seeking one and only session object!
Please guide me to understand. Thank you.
Author and all-around good cowpoke
Joined: Mar 22, 2000
if there are thousands of concurrent requests for one mail session object,
I have not examined the source code, but I get the impression from the JavaDocs that a session just serves as a "data object" that organizes all of the parameters needed in one place. If an object does not contain any variables that are altered by users, there is no reason you can't have thousands of "concurrent" users. Basically the same principle that lets one servlet instance handle any number of requests "simultaneously."
If you are worried about it, get the source code and look for variables that get modified by users.
I am getting more confused... I think I must ask the question differently.. so that I can understand it better...
As in the case of database connections: in our tomcat application there are several servlets and according the user requests there are many threads running and seeking database connection to fetch the desired result from the database. Because there are thousands of threads seeking database connection. We create database connection pool so that when one such connection is being utilized the other connection which is free to serve can be used. Here in this case one database connection is insufficient to handle the several concurrent requests at a time.
Similarly if we have one mail session object to serve then would it server to all threads out of the servlets, requesting to get the session to send mail!
When you see connection pools routinely being used, but mail session pools not being used, in a product which is used by probably hundreds of thousands of people, doesn't it lead you to believe that mail session pools aren't necessary?
You don't seem to be asking because you're having a problem. So I would suggest that you don't have a problem.
Thank you William for patiently replying and answering to understand the subject.
Paul thank you! I understood the mail session pools are not necessary. Only one mail session object is sufficient even when my application is having multiples of thousands of users intensively utilizing the session object.
Well, yours might be the one application in a million for which your usage of mail sessions is so heavy that you need to do something special. But I rather doubt it. Presumably you aren't having problems with these thousands of users right now?