Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Threads in j2ee

 
Raef Kandeel
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is it prohibited to use threads in jsp's. If I have a class, not a bean, that uses threads. Just the line:-



is it considered a bad practice?

Thanks
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34372
345
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raef,
It's considered bad practice to have any code in a JSP. It's considered horrible practice to have a sleep statement in a JSP.

A JSP is supposed to be the view layer. All logic should be done in a servlet (or code called by a servlet) before forwarding to the JSP.

What are you trying to accomplish? Maybe we could suggest a better way.
 
Raef Kandeel
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh Oh. That was a mistake. No, I used Thread.sleep in a java class, not in JSP. You can replace JSP with J2EE. Thanks for your reply.
[ April 12, 2008: Message edited by: Raef Kandeel ]
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34372
345
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raef,
That's a more interesting question.

Using threads in EJBs is not considered good practice. In a servlet, I've seen it. I wouldn't call it good practice, but there are a couple uses. All of which can now be replaced with AJAX or queues.

I think the real question is whether thread.sleep is the best way for what you are trying to accomplish. Feel free to give an example.
 
Raef Kandeel
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am aware that some web application servers have schedulers that fulfill the same functionality. I know that WAS does for example. Is there any simpler solution. What I am trying to achieve here is automatically retrieve some rss feed every specified time interval. Thanks again.
[ April 14, 2008: Message edited by: Raef Kandeel ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic