Isn't it hard to get something back from ServletContext as the caller is whatever class outside the Container's environment?
[ November 12, 2007: Message edited by: Maximilian Boonyoung ]
How is it used and by what components; by just one servlet or by multiple components within your app?
Originally posted by Max Bean:
All would be done in single servlet. I have a scenario of using ThreadPool to store the user requests before persist to database if the number of threads is high enough. And then, at persist time, I will fetch those threads into the running processes.
When you say "store the request" you aren't talking about keeping a reference to the actual HttpServletRequest object passed to your servlet by the container, do you?
Unless you using a single thread servlet which is not recommended.
If you have long functions to perform, then launch a worker thread.
But I think you maybe wanting to set up a dB pool, which is not about threads its about a collection of dB connections, not the same thing.
Also I think you think that every thread gets a new servlet class, for the default servlet model that is not the case. You dont have to use static variables, because all the request threads are running through the SAME servlet instance.... remember that.
Yes INIT is made for you to set up the servlet, but be very careful will global variables... all those request threads come through that servlet.
There are db Pools on the web especially made for this purpose, or you can use the containers pool which normally comes in through JNDI.
There is already a thread pool for the request threads, and they dont queue, you could have 5 threads running through that servlet at the same time already... you do not have to try and help it, but you do need to watch thread safety and global variables are bad news...