dcsimg
JavaMail/Threading Problem
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Rakesh_Patel
Posted On:   Friday, February 18, 2005 12:37 AM

Got the task of debugging following piece of Code. The send method of SendMail is called in JSP. This Code would work Locally in WebSphere Site Developer (Windows) but jumbled the mail message in the Production Env.(Sun Solaris) After removing the "synchronized" keyword from the send method, it worked fine in the Production Env.(Sun Solaris). Need to know the reason for "synchronized" causing problem. The code is not perfect, wld need lot of modification but in as is state need to know the reason for "synchronized" causing the problem. public class SendMail { public synchronized void send(String from,String to, in   More>>

			

Got the task of debugging following piece of Code. The send method of SendMail is called in JSP.

This Code would work Locally in WebSphere Site Developer (Windows) but jumbled the mail message in the Production Env.(Sun Solaris)

After removing the "synchronized" keyword from the send method, it worked fine in the Production Env.(Sun Solaris).

Need to know the reason for "synchronized" causing problem.


The code is not perfect, wld need lot of modification but in as is state need to know the reason for "synchronized" causing the problem.

public class SendMail

{

public synchronized void send(String from,String to,

int requestId,String resolverName)

throws MessagingException

{

Transport trns = null;

try

{



// Create a mail session

Properties props = new Properties();

props.put(

"mail.smtp.host",

HelpdeskProperty.getPropertyValue("smtphost"));

Session session = Session.getInstance(props, null);

session.setDebug(false);



// Construct the message

Message msg = new MimeMessage(session);

msg.setFrom(new InternetAddress(from));

msg.addRecipient(Message.RecipientType.TO, new InternetAddress(to));

msg.setSubject(

HelpdeskProperty.getPropertyValue("emailsub1")

+ requestId + " "

+ HelpdeskProperty.getPropertyValue("emailsub2"));

msg.setText(

HelpdeskProperty.getPropertyValue("emailbody1")

+ " " + resolverName + " "

+ HelpdeskProperty.getPropertyValue("emailbody2")

+ requestId

+ HelpdeskProperty.getPropertyValue("emailbody3"));



// Send the message

Transport.send(msg);

}

catch (Exception e)

{

System.out.println(

"Exception occured in sending mail to the initiator " + e);

}



}

}





public class HelpdeskProperty

{

static Properties prop = new Properties();

public static String getPropertyValue(String propName)

{

String propValue="";

try

{

InputStream is = HelpdeskProperty.class.getClassLoader().getResourceAsStream("helpdsk.properties ");

prop.load(is);

is.close();

propValue=prop.getProperty(propName);

System.out.println("Property " + propName + "=" + propValue);

}

catch (Exception e)

{

System.out.println("Exception occured in getting property " +propName+" from properties file "+e);

}

return propValue;

}

}

   <<Less
About | Sitemap | Contact