You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Lionel Farbos <li...@free.fr> on 2005/04/01 12:39:13 UTC

Re: [OT] Proper way to open threads in a servlet

Your question is not really Tomcat so I put it Off Topic.

On Fri, 1 Apr 2005 15:24:10 +1000
"Steve Vanspall" <st...@crmsoftware.com.au> wrote:

> Hi there,
> 
> I am concerned that opening a thread in my serlvet using new Thread(Runnable) style code, is causing a massive hang in my system.
> 

I don't understand why this hang your system !?...
You can't do like this but don't forget to daemonize your thread.

If you don't want your thread to run in the same JVM as Tomcat,
you can send a message to a daemon; then the daemon (in another JVM and/or another server) will receive the messages and treat them (in new Threads).
To send messages, you can use JMS (so, you need a JMS server) or sockets TCP or UDP (see java.net).



> Basically what the thread does is email people to notify them of a change in an order on the system.
> 
> I want the emails to be sent in a separate thread so that the user doesn't have to wait for this to complete to return to the system.
> 
> Basically the email is a non crucial part, the action has already been performed. I know this isn't specifically a Tomcat question, but I thought I would ask it anyway.
> 
> The two ways this could work is that the email is placed in a queue, that is checked periodically, or just somehow the email(s) are sent in the background, but without opening a new thread using code.
> 
> Can anyone give me some pointers on how to do this. Yes I have been searching around, but haven't found much information.
> 
> Tahnks in advance
> 
> Steve
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: [OT] Proper way to open threads in a servlet

Posted by QM <qm...@brandxdev.net>.
On Fri, Apr 01, 2005 at 11:45:40AM +0100, Mark Benussi wrote:
: I would place your e-mail in a MailManager that queues the messages and
: sends them out on a TimerTask (Every 10 seconds???).

Why not just use JMS?  The servlet puts messages in a queue and returns
to the user. In turn, a queue listener turns those messages into
e-mails.  [solves the problem of delaying the user response while
e-mails are sent]

If you don't have a separate server/service to run the queue listener,
do that inside a single Tomcat thread that is created/destroyed by a
ServletContextListener. [solves the thread hanging problem, as well as
the too-many-threads problem.]

-QM

-- 

software   -- http://www.brandxdev.net/
tech news  -- http://www.RoarNetworX.com/
code scan  -- http://www.JxRef.org/

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: [OT] Proper way to open threads in a servlet

Posted by Lionel Farbos <li...@free.fr>.
On Fri, 1 Apr 2005 11:45:40 +0100
"Mark Benussi" <ma...@hotmail.com> wrote:

> I would place your e-mail in a MailManager that queues the messages and
> sends them out on a TimerTask (Every 10 seconds???).
> 
> Secondly from a pernickety perspective I would not have a Servlet doing any
> of what you described. At least place this code a level down in a Manager
> class that can coordinate with the MailManager.
> 
But the MailManager you speak about, doesn't exist in Tomcat.
So, it runs in the Tomcat's jvm (I understood Steve didn't want this) or in other jvm ?
And, if it is in another jvm, how your servlet communicate with the MailManager ?

Rather than TimerTasks, a good issue for these needs could be Quartz (http://www.opensymphony.com/quartz/)

> -----Original Message-----
> From: Lionel Farbos [mailto:lionel.farbos@free.fr] 
> Sent: 01 April 2005 11:39
> To: Tomcat Users List
> Cc: steve@crmsoftware.com.au
> Subject: Re: [OT] Proper way to open threads in a servlet
> 
> Your question is not really Tomcat so I put it Off Topic.
> 
> On Fri, 1 Apr 2005 15:24:10 +1000
> "Steve Vanspall" <st...@crmsoftware.com.au> wrote:
> 
> > Hi there,
> > 
> > I am concerned that opening a thread in my serlvet using new
> Thread(Runnable) style code, is causing a massive hang in my system.
> > 
> 
> I don't understand why this hang your system !?...
> You can't do like this but don't forget to daemonize your thread.
> 
> If you don't want your thread to run in the same JVM as Tomcat,
> you can send a message to a daemon; then the daemon (in another JVM and/or
> another server) will receive the messages and treat them (in new Threads).
> To send messages, you can use JMS (so, you need a JMS server) or sockets TCP
> or UDP (see java.net).
> 
> 
> 
> > Basically what the thread does is email people to notify them of a change
> in an order on the system.
> > 
> > I want the emails to be sent in a separate thread so that the user doesn't
> have to wait for this to complete to return to the system.
> > 
> > Basically the email is a non crucial part, the action has already been
> performed. I know this isn't specifically a Tomcat question, but I thought I
> would ask it anyway.
> > 
> > The two ways this could work is that the email is placed in a queue, that
> is checked periodically, or just somehow the email(s) are sent in the
> background, but without opening a new thread using code.
> > 
> > Can anyone give me some pointers on how to do this. Yes I have been
> searching around, but haven't found much information.
> > 
> > Tahnks in advance
> > 
> > Steve
> > 
> > 
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> > 
> > 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


RE: [OT] Proper way to open threads in a servlet

Posted by Mark Benussi <ma...@hotmail.com>.
I would place your e-mail in a MailManager that queues the messages and
sends them out on a TimerTask (Every 10 seconds???).

Secondly from a pernickety perspective I would not have a Servlet doing any
of what you described. At least place this code a level down in a Manager
class that can coordinate with the MailManager.

-----Original Message-----
From: Lionel Farbos [mailto:lionel.farbos@free.fr] 
Sent: 01 April 2005 11:39
To: Tomcat Users List
Cc: steve@crmsoftware.com.au
Subject: Re: [OT] Proper way to open threads in a servlet

Your question is not really Tomcat so I put it Off Topic.

On Fri, 1 Apr 2005 15:24:10 +1000
"Steve Vanspall" <st...@crmsoftware.com.au> wrote:

> Hi there,
> 
> I am concerned that opening a thread in my serlvet using new
Thread(Runnable) style code, is causing a massive hang in my system.
> 

I don't understand why this hang your system !?...
You can't do like this but don't forget to daemonize your thread.

If you don't want your thread to run in the same JVM as Tomcat,
you can send a message to a daemon; then the daemon (in another JVM and/or
another server) will receive the messages and treat them (in new Threads).
To send messages, you can use JMS (so, you need a JMS server) or sockets TCP
or UDP (see java.net).



> Basically what the thread does is email people to notify them of a change
in an order on the system.
> 
> I want the emails to be sent in a separate thread so that the user doesn't
have to wait for this to complete to return to the system.
> 
> Basically the email is a non crucial part, the action has already been
performed. I know this isn't specifically a Tomcat question, but I thought I
would ask it anyway.
> 
> The two ways this could work is that the email is placed in a queue, that
is checked periodically, or just somehow the email(s) are sent in the
background, but without opening a new thread using code.
> 
> Can anyone give me some pointers on how to do this. Yes I have been
searching around, but haven't found much information.
> 
> Tahnks in advance
> 
> Steve
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org