• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is it a good idea to spawn a thread from a servlet?

 
Sajee Joseph
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have an application which generates reports. Currently this is already in place. Here a servlet (A) invokes another servlet (B) to get the job done. Now i have a new requirement to run multiple reports at a time. I have done it in a sequential manner. Thus A invokes B several times one after another. For the generate of each report a DB2 sp is invoked ( which get the Report data). Actually the DB2 sp is time sonsuming & it take an average of 15 mins. Thus if i have 5 reports to be run it will take an avg of 15 * 5 = 75 mins.
I have 2 queries:
1. If i do this in a multithreaded way ( by spawning different threads for each reports form Servlet A )will it help reducing the time?
2. Is it a good idea to spawn a thread from a servlet?

Regard,
Saj
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Multiple reports at a time? Is it for one user or multiple user.
- If multiple user then servlet is already multithreaded.
- If one user, then why need multiple reports simultaneously?

I think you need to tune your SQL or DB.
- Indexes must be there on appropriate columns. Specifically on columns which participates in condition
- ORing should be after ANDing
- Use LIKE operator instead of functions like substr(), if any is being used.
 
Sajee Joseph
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is for One User. Multiple reports run simultaneously for 1 user. For each report a .csv file is generated
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would avoid it if possible.
Threads started from within web apps can have adverse effects when trying to reload the application and/or restart the server.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This sounds like a candidate for an asynchrous process - since the DB operation is so time consuming, you can't reasonably expect the user to wait for a response. Perhaps JMS to generate the reports and JavaMail to delover them?

I have to agree with Adeel Ansari though, if this is taking so long you might want to review your DB configuration and/or how you've written your Stored Precedures.
[ March 29, 2005: Message edited by: Paul Sturrock ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic