• Post Reply Bookmark Topic Watch Topic
  • New Topic

Usage of Threads in Web applications  RSS feed

 
Avianu Sud
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.

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
 
Stan James
(instanceof Sidekick)
Ranch Hand
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
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!