Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts not multithreaded?

 
J.H.B. Oosterlaar
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I was thinking. The Action dispatching is not multithreaded. In other words: the Action does nog extends Thread nor does it implements Runnable.
What is the reason for this? When there are many client requests, there will be a waitbuffer, won't there be? Request are handled after eachother.
Could anyone explain this? We are developing a dispatcher that dispatches jobs to actions that need to be Threads, because they extract data from the database. In order to not slowing down other requests, we made it an extension of Thread.
Thanks and cheers,
Jeroen Oosterlaar
 
David Weitzman
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know much about Struts, but from the Struts Javadocs:
Actions must be programmed in a thread-safe manner, because the controller will share the same instance for multiple simultaneous requests
 
corneliu mamut
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by J.H.B. Oosterlaar:
Hi,
I was thinking. The Action dispatching is not multithreaded. In other words: the Action does nog extends Thread nor does it implements Runnable.

You are right. But
public class ActionServlet
extends HttpServlet {
...
}
So the ActionServlet class is an servlet (multithreaded - the threads are managed by your servlet container). The execute() or perform() methods are called from ActionServlet (or your ActionServlet).
See also
http://www.javaranch.com/newsletter/Mar2002/newslettermar2002.jsp
[ March 20, 2003: Message edited by: corneliu mamut ]
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Struts runs through servlets so multi-threading is not an issue.
 
J.H.B. Oosterlaar
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I found out myself. Threads aren't even possible. Say I develop my own dispatcher. My actions are extensions of Thread. When I pass the request object to that action, it cannot be used anymore. The reference is lost. Thanks for the comments.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic