• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Running a quote in threads.

 
Faisal Khan
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am not sure if this is a beginner question or intermediate so sorry if its too basic. I have a JSP page which will display special offer cars we have ( could have 0 - 10 cars ).
There is a for loop, where I fetch the the list of special cars and inside the loop run a quote on each, using the following:
SpecialOffersCalc soc = new SpecialOffersCalc(corporateID, row);
followed by displaying the results. This takes around 10 - 12 seconds to do for 3-4 cars.
I thought may be the speed can be improved by making SpecialOffersCalc "Runnable" and inside the loop do the following:

Now the page gets displayed in a seconds or so but all results are null
Have I completely lost the plot or am I along the right lines, what can I try to fix this.
Thanks in advance.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to collect the results back in your main thread somehow. You could use a simple callback or make your main thread a listener for bean style events published by the calculator threads.
If you have an Swing front end, look at SwingUtilities.invokeLater() to put the update events back on the Swing thread. Otherwise they won't display when you think they should.

A couple notes: I made the results come back out of sequence. Could happen. And you may want to synchronize the callback method because all the calculators could call back at once.
Hope that helps!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic