aspose file tools*
The moose likes Java in General and the fly likes Running a quote in threads. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Running a quote in threads." Watch "Running a quote in threads." New topic
Author

Running a quote in threads.

Faisal Khan
Ranch Hand

Joined: Jun 29, 2003
Posts: 285
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.


The secret to creativity is knowing how to hide your sources.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
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!


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Running a quote in threads.