Firefox 3 hangs when executing background thread - Mozilla

This is a discussion on Firefox 3 hangs when executing background thread - Mozilla ; Hi! I'm developing a Firefox 3 extension and I'm currently trying to use multithreading. My problem at the moment is, that a background thread executes my code, but the main thread hangs nevertheless. Sometimes Firefox even crashes. The execution engine ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: Firefox 3 hangs when executing background thread

  1. Firefox 3 hangs when executing background thread

    Hi! I'm developing a Firefox 3 extension and I'm currently trying to use
    multithreading.

    My problem at the moment is, that a background thread executes my code,
    but the main thread hangs nevertheless. Sometimes Firefox even crashes.

    The execution engine is a Java object which is used via LiveConnect.
    Could it be that the Java Code is always executed on the main thread?
    The command this.execution_engine.createCall(this.data); may need
    several minutes. The browser hangs while executing the command.

    I took the following link as a guideline for multithreading in firefox:
    http://developer.mozilla.org/en/docs/The_Thread_Manager

    Any pointers?
    Thanks!
    Steffen

    P.S.:
    My code looks like this:

    ....
    var wm =
    Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediato r);
    var browserWindow = wm.getMostRecentWindow("navigator:browser");
    var browser = browserWindow.getBrowser().getBrowserAtIndex(tabNu mber);

    //try to generate new Thread
    var myEEThread =
    Components.classes["@mozilla.org/thread-manager;1"].getService().newThread(0);
    myEEThread.dispatch(new EERunnable(1, execution_engine, browser, data,
    myEEThread), myEEThread.DISPATCH_NORMAL);

    // ******* execution engine runnable ***
    var EERunnable = function(threadID, execution_engine, browser, data,
    thread) {
    this.threadID = threadID;
    this.execution_engine = execution_engine;
    this.browser = browser;
    this.data = data;
    this.thread = thread;
    };

    EERunnable.prototype = {
    run: function() {
    try {
    dump("EEThread started\n");
    var result = this.execution_engine.createCall(this.data);
    dump("returned from ee.create call");
    var main =
    Components.classes["@mozilla.org/thread-manager;1"].getService().mainThread;
    dump("retrieved main thread");
    main.dispatch(new mainThreadRunnable(this.threadID, this.browser,
    result), this.thread.DISPATCH_NORMAL);
    dump("dispatched main thread runnable on main thread\n");
    } catch(err) {
    dump(err + "\n");
    Components.utils.reportError(err);
    }
    },

    QueryInterface: function(iid) {
    if (iid.equals(Components.interfaces.nsIRunnable) ||
    iid.equals(Components.interfaces.nsISupports)) {
    return this;
    }
    throw Components.results.NS_ERROR_NO_INTERFACE;
    }
    };

    // ********************** main thread runnable ************
    var mainThreadRunnable = function(threadID, browser, result) {
    this.threadID = threadID;
    this.browser = browser;
    this.result = result;
    };

    mainThreadRunnable.prototype = {
    run: function() {
    try {
    dump("main thread started\n");
    this.browser.contentDocument.getElementById("result").innerHTML =
    this.result;
    dump("wrote result back to tab\n");
    } catch(err) {
    Components.utils.reportError(err);
    }
    },

    QueryInterface: function(iid) {
    if (iid.equals(Components.interfaces.nsIRunnable) ||
    iid.equals(Components.interfaces.nsISupports)) {
    return this;
    }
    throw Components.results.NS_ERROR_NO_INTERFACE;
    }
    };

  2. Re: Firefox 3 hangs when executing background thread

    Steffen Heinzl wrote:

    > var browser = browserWindow.getBrowser().getBrowserAtIndex(tabNu mber);


    > myEEThread.dispatch(new EERunnable(1, execution_engine, browser, data,


    DOM objects are by default not threadsafe (they're main thread only).

    Note that if this JS is in a DOM window (from a