Hmm.. I read the spec again- it seems to imply that I CAN start my own
threads in a servlet container.
So maybe a TimerTask will do- or a simple Thread.sleep
I dont need to have it happen periodically or anything.
Just want the incoming request to poll a resource a couple of times
before giving up.
Thanks
A
> Hmm.. I read the spec again- it seems to imply that I CAN start my own
> threads in a servlet container.
[quoted text clipped - 6 lines]
> Thanks
> A
You can spawn threads from a servlet container. I guess you're mixing
J2EE Server, EJB Container and a Servlet Container. It is recommended
not to spawn threads from an EJB as the container manages the thread
pool(s), bean state and transactions which threading can interfere
with.
As far as the Servlet Containers go, they spawn 1 thread per request
which runs a single instance's service() method (Unless the servlet
implements singlethreadmodel, where there will be 1 servlet instance
per thread per request). Anyway, when you make the thread wait, there
is a chance that when multiple requests for the same requests come in,
and the server has n threads waiting, it might run out of threads in
the pool and queue up the requests, eventually timing out if the
threads take forever. Some containers (tomcat) are smart enough to
pool serveral servlet instances. Either way, there is a high chance of
running out of threads from the container pool if the threads block
forever, or the servlet gets way too many requests.
These are just some things to consider - a lot has to do with the
requirements of your app, and the usability.
-cheers,
Manish
Arne Vajhøj - 19 Aug 2007 03:08 GMT
> It is recommended
> not to spawn threads from an EJB as the container manages the thread
> pool(s), bean state and transactions which threading can interfere
> with.
I think "recommended" is understating.
#• The enterprise bean must not attempt to manage threads. The
enterprise bean must not attempt
#to start, stop, suspend, or resume a thread, or to change a thread’s
priority or name. The enterprise
#bean must not attempt to manage thread groups.
Arne
> Hmm.. I read the spec again- it seems to imply that I CAN start my own
> threads in a servlet container.
[quoted text clipped - 3 lines]
> Just want the incoming request to poll a resource a couple of times
> before giving up.
You are allowed to do it from a servlet.
If it is something only a single or few users are
doing it is also OK.
If many users will be doing it then you can get
problems with the server.
Why not do it another way like:
- have one request send a message to a message queue
- have a MDB process it
- have the client poll at a reasonable interval to a
servlet that checks if the work is done
?
I would think the container would prefer 3*N requests
that runs quick over N requests that each blocks for
seconds.
Arne