What is the best way to parallelize calls in JSP?

advertisements

My understanding of JSP is that each line in the java code is run step by step (in sequence). E.g. if I have a code below, doSomething("apple") will be executed first until it returns a value, then doSomething("orange") will be executed next until it returns a value, then finally doSomething("pear") will be executed until it returns a value and the whole page is displayed.

<table border="1">
    <thead>
        <tr>
            <th>Test</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Column A</td>
            <td><%=javaBean.doSomething("apple")%></td>
        </tr>
        <tr>
            <td>Column B</td>
            <td><%=javaBean.doSomething("orange")%></td>
        </tr>
        <tr>
            <td>Column C</td>
            <td><%=javaBean.doSomething("pear")%></td>
        </tr>
    </tbody>
</table>

What is the best way to make these calls parallel e.g. run doSomething("apple") & doSomething("orange") & doSomething("pear") concurrently? Thank you.


You shouldn't do this in JSP, it's designed to render in a single thread. If the page is too slow, the usual method these days is to have a fast loading page with three placeholders. Then load the slow parts with AJAX. These can make concurrent calls back to the server to load the rest.