WebSphere Application Server - Sending a mail from a Custom Service ?

This is Interesting: Free IT Magazines  
Home > Archive > WebSphere Application Server > July 2005 > Sending a mail from a Custom Service ?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Sending a mail from a Custom Service ?
Ben_

2005-07-29, 2:56 am

Hello,

Building on the sample CustomServiceThreadHungMBean, I was thinking of
sending a mail when I identify some interesting thread hang conditions.

But reading the following from the InfoCenter, I wonder if it is legal to do
so:
"
(...)
Creation of sockets and I/O, other than file I/O, is not supported.
Execution of standard J2EE code (client code, servlets, enterprise beans) is
not supported.
(...)
Some JNDI operations are available.
"
(http://publib.boulder.ibm.com/infoc....jsp?topic=/com
..ibm.websphere.base.doc/info/aes/ae/trun_customservice.html)

This raises a few questions about the design:
* Sending a mail will cause network I/O, but is it considered I/O and is it
a legal operation ?
* Would it be legal to look up a MailSession from the JNDI instead and use
it to send mails ?
* I thought it'd be better to send the mail in the background (in a separate
thread, to avoid the risk of blocking the Notification thread in case of
timeouts, etc). But threading in not
supported. Question: Better override the rule or stick to it ? (at the risk
of blocking
the notification thread (in the event of timeouts when sending mails, etc).
But does the Notification block after all ?
* Again about threading: if my own class does not spawn threads, but use a
library that has a background thread (like Log4J's configuration watcher
thread), is it legal to use it ?

Questions are merely about legality than about working or not (I now have a
CustomService that does the lookup of a JNDI Mail Session and sends
e-mails -- it sends mails synchronously however).

Thanks for your advise.


Ken Hygh

2005-07-29, 8:09 am

Ben_ wrote:

>Hello,
>
>Building on the sample CustomServiceThreadHungMBean, I was thinking of
>sending a mail when I identify some interesting thread hang conditions.
>
>But reading the following from the InfoCenter, I wonder if it is legal to do
>so:
>"
>(...)
>Creation of sockets and I/O, other than file I/O, is not supported.
>Execution of standard J2EE code (client code, servlets, enterprise beans) is
>not supported.
>(...)
>Some JNDI operations are available.
>"
>(http://publib.boulder.ibm.com/infoc....jsp?topic=/com
>.ibm.websphere.base.doc/info/aes/ae/trun_customservice.html)
>
>

First thing to remember - your MBean isn't J2EE code. JMX isn't even
part of the J2EE 1.4 spec - though JavaMail is.

>This raises a few questions about the design:
>* Sending a mail will cause network I/O, but is it considered I/O and is it
>a legal operation ?
>
>

It's legal. Remember that calling a remote EJB will result in network
I/O, but is perfectly legal - because it's controlled by the container.
So is JavaMail.

>* Would it be legal to look up a MailSession from the JNDI instead and use
>it to send mails ?
>
>

It's always legal to do this, even in J2EE components.

>* I thought it'd be better to send the mail in the background (in a separate
>thread, to avoid the risk of blocking the Notification thread in case of
>timeouts, etc). But threading in not
>supported. Question: Better override the rule or stick to it ? (at the risk
>of blocking
>the notification thread (in the event of timeouts when sending mails, etc).
>But does the Notification block after all ?
>
>

Again, MBeans aren't J2EE components, so do any threading you want.

>* Again about threading: if my own class does not spawn threads, but use a
>library that has a background thread (like Log4J's configuration watcher
>thread), is it legal to use it ?
>
>Questions are merely about legality than about working or not (I now have a
>CustomService that does the lookup of a JNDI Mail Session and sends
>e-mails -- it sends mails synchronously however).
>
>Thanks for your advise.
>
>
>
>

Ken
Ben_

2005-07-29, 6:14 pm

Ken,

Thanks for your knowledgeable input (as usual :-).

My quote of the InfoCenter was not complete. Actually, I realize I removed a
line I shouldn't had, which says: "Creation of thread is not supported."
(http://publib.boulder.ibm.com/infoc....jsp?topic=/com
..ibm.websphere.base.doc/info/aes/ae/trun_customservice.html)

It's in a topic specific to Custom Services and not J2EE.

Do you still state that, to you, one can do any threading in a Custom
Service ?


Ken Hygh

2005-07-29, 6:14 pm

Ben_ wrote:

>Ken,
>
>Thanks for your knowledgeable input (as usual :-).
>
>My quote of the InfoCenter was not complete. Actually, I realize I removed a
>line I shouldn't had, which says: "Creation of thread is not supported."
>(http://publib.boulder.ibm.com/infoc....jsp?topic=/com
>.ibm.websphere.base.doc/info/aes/ae/trun_customservice.html)
>
>It's in a topic specific to Custom Services and not J2EE.
>
>Do you still state that, to you, one can do any threading in a Custom
>Service ?
>
>
>
>

Well, I *have* done it :-). Doesn't mean that I could open a bug with
IBM if I run into problems.

Just need to make sure that you implement shutdown() and it kills the
thread, and I usually call Thread.setDaemon(true) before calling run(),
and you're limited in what J2EE thingies you can call, because you
don't, for instance, have a security context, etc. etc.

Ken
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com