This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Hands On Software Engineering with Python and have Brian Allbey on-line!
See this thread for details.
Win a copy of Hands On Software Engineering with Python this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

Usage of Threads in Web applications  RSS feed

Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have NO instance variables in HttpServlet classes, and all calls to helpers are either local instance variables, or static calls for data that is displayed on JSP pages.


class ShoppingCart extends HttpServlet {

public void execute() {
int selectedBook = request.getAttribute("bookId");
Delegate delegate = new Delegate();
Book book = delegate.getBookDetail(selectedBook);
ArrayList authors = delegate.getAuthorDetails(selectedBook);

request.setAttribute("bookDetail", book);
request.setAttribute("authorDetail", authors);

// show book detail or forward to jsp page...

I have not seen any need to make any code ThreadSafe in this case.
1) Is there any situation that will fail the application?
2) How much are Threads used in High transaction Web based applications? (Extensive/Minimal/As needed?)

Please share your expertise,
- Avi
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like you're following safe practices well. Unless the delegate could give the same Book instance to two servlets at the same time, which is probably not the case.

The container uses threads like crazy, but application developers rarely do in servlets. You'll see conversations here about running a thread that does some action periodically, like an hourly database update or something. I wouldn't expect more than a handful of those ever.

It's also possible to start a thread to do some work for the user and return immediately. It's tricky to get the results back to the user when you do that and it's not common.
Avianu Sud
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Very Insightful response. Thank You.

PS. I ususally rely on Timers and Messaging for batch and external system processing(which also handle Threads internally).

I just get a bit concerned when technologists keep making Threads as a Primary issue in Web Based Applications.

My perspective: Threads are critical, but mostly handled by Containers for us.
A "dutch baby" is not a baby. But this tiny ad is baby sized:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!