once your request go to the servlet your servlet makes new thread to process your request. At that time you have no holdover your code. So I think it is not necessary and adviseable ...
If it's been flushed and closed I don't really see how.
Seems like it'd be *really* easy to test by putting in a sleep.
James Hodgkiss
Ranch Hand
Joined: Jan 22, 2004
Posts: 401
posted
0
Yes, I put in a sleep and it was fine, but I have heard of some people experiencing problems with this sort of thing... So I was just wondering if there was a particular best practice to adopt... I'll keep it in the same Thread anyway. Thanks all.
Well, in theory, you're not supposed to do your own thread management in EE containers.
Max Rahder
Ranch Hand
Joined: Nov 06, 2000
Posts: 177
posted
0
James Hodgkiss wrote:Once my servlet has sent its response to the client, it may do some other stuff like modifying a database and/or sending an email. Q: Is it best practice to do that extra stuff in a new Thread (so my processRequest() method returns asap) or is that not necessary/adviseable?
Thanks,
James
I don't know about the Best Practice part, but I see nothing wrong with using a thread to avoid blocking the user's response. If the failure of the db call, or whatever, will affect the response, then obviously you would *want* to wait until that completes or fails before sending the response. But if the success or failure of that action is transparent to the user, then using a spawned thread seems fine to me.
M. Justin
Greenhorn
Joined: Sep 03, 2009
Posts: 15
posted
0
James Hodgkiss wrote:Once my servlet has sent its response to the client, it may do some other stuff like modifying a database and/or sending an email.
Q: Is it best practice to do that extra stuff in a new Thread (so my processRequest() method returns asap) or is that not necessary/adviseable?
Thanks,
James
A very common solution for asynchronous processing in an EE container would be a JMS message queue. The servlet just passes the necessary information as a JMS message, and sends it to a queue. A message driven bean then would pick up the message and process the database / email stuff.
M. Justin wrote:A very common solution for asynchronous processing in an EE container would be a JMS message queue. The servlet just passes the necessary information as a JMS message, and sends it to a queue. A message driven bean then would pick up the message and process the database / email stuff.