• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Usage of Threads in Web applications

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

Example:

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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
James,

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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic