wood burning stoves 2.0*
The moose likes Tomcat and the fly likes Creating JavaMail session pool Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Creating JavaMail session pool" Watch "Creating JavaMail session pool" New topic
Author

Creating JavaMail session pool

ramnna jain
Ranch Hand

Joined: Mar 16, 2009
Posts: 129

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.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12681
    
    5
Is there some reason a javax.mail.Session cant just be re-used? The JavaDocs suggest one session can be used by multiple applications.

Bill

Java Resources at www.wbrogden.com
ramnna jain
Ranch Hand

Joined: Mar 16, 2009
Posts: 129

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.

Please correct me if I am wrong...
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18135
    
    8

That didn't sound like a reason why sessions can't be reused.
ramnna jain
Ranch Hand

Joined: Mar 16, 2009
Posts: 129

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.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12681
    
    5
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.

Please let us know if you find any.

Bill
ramnna jain
Ranch Hand

Joined: Mar 16, 2009
Posts: 129

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!

I am thankful to your help and time.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18135
    
    8

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.
ramnna jain
Ranch Hand

Joined: Mar 16, 2009
Posts: 129

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.

Thank you.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18135
    
    8

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?
ramnna jain
Ranch Hand

Joined: Mar 16, 2009
Posts: 129

Paul thank you! Thank you very much.... for your suggestion and dignosing capability... thank you...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creating JavaMail session pool
 
Similar Threads
how to send email using ejb
How to Increase the Pool size for SLSB
Java Mail
How to set Multilanguage Subject in Javax.mail
java mail api