This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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.
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