Increasing performance through Threading







Threading and performance

The performance of the Server Edition can be improved where several calls are made to the browser. Multiple operations such as DOM functions can be run at once on the WebRenderer thread to reduce communication between the Java and native browser code and increase execution speed. The methods specifically designed for improved performance are the IBrowserCanvas.invokeLater(), IBrowserCanvas.invokeAndWait() methods.

The design of the invoke and invokeAndWait is similar to the way that operations can be run on the Swing thread with SwingUtilities, by calling the browser functions inside a Runnable. As with SwingUtilities, there two methods for doing this, invokeLater and invokeAndWait.

The invokeLater method wil execute the code when it has finished tasks in the current thread.

The invokeAndWait method executes the code when called and will wait until the code inside the Runnable has completed before continuing.

The following is an example of executing DOM code inside invokeAndWait:

IBrowserCanvas browser;
browser.invokeAndWait(new Runnable() {
        public void run() {
                // List all the element tags in an HTML document.
                IDocument doc = browser.getDocument();
                IElementCollection all = doc.getAll();
                for (int i=0; i<all.length(); i++) {
                        IElement elm = all.item(i);
                        if (elm != null) {
                                if (elm.isTextNode()) {
                                        System.out.println( elm.getTextNodeText() );
                                } else {
                                        System.out.println( elm.getTagName() );






 Copyright JadeLiquid Software - www.jadeliquid.com