This Question is Possibly Answered

1 "correct" answer available (4 pts) 2 "helpful" answers available (2 pts)
2 Replies Last post: Aug 17, 2010 6:38 PM by Scott Torrance  
Steve   4 posts since
Feb 5, 2010
Currently Being Moderated

Feb 5, 2010 7:24 PM

Main message loop thread is already stopped error in JExplorer

Hi,

 


I'm getting the following exception once in a while and have a hard time reduplicating this issue.  Unfortunately, when it does occur, I can no longer open any web pages via JExplorer.  Any ideas how to fix this?

 


Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: Main message loop thread is already stopped.
    at com.jniwrapper.win32.MessageLoopThread.checkRunning(MessageLoopThread.java:258)
    at com.jniwrapper.win32.MessageLoopThread.doInvokeAndWait(MessageLoopThread.java:185)
    at com.jniwrapper.win32.ie.OleMessageLoopUtilities.invokeAndWait(Unknown Source)
    at com.jniwrapper.win32.ie.bp.navigate(Unknown Source)
    at com.jniwrapper.win32.ie.db.navigate(Unknown Source)
    at com.jniwrapper.win32.ie.db.navigate(Unknown Source)
    at com.jniwrapper.win32.ie.Browser.navigate(Unknown Source)
    at com.amt.jexplorer.BrowserInvoker.showInternalBrowser(BrowserInvoker.java:122)
    at com.amt.jexplorer.BrowserInvoker.show(BrowserInvoker.java:97

 

    ...

 

 

I put the code for the BrowserInvoker object below.

 

Thanks,

Steve

 

----------------------------------------------------

 


package com.amt.jexplorer;

 


import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

 


import javax.swing.JFrame;
import javax.swing.JTabbedPane;

 


import com.jniwrapper.win32.ie.Browser;
import com.jniwrapper.win32.ie.event.DisposeEvent;
import com.jniwrapper.win32.ie.event.DisposeListener;

 

 

 

/**
*    Browser frame
*/
public class BrowserInvoker {

 


    /**
    *    Maximum number of tabs (URLs) allowed to be opened at once
    */
    private final static int MAX_NUM_TABS = 5;
  
    /**
    *    Singleton instance
    */
    private final static BrowserInvoker _instance = new BrowserInvoker();
  
    /**
    *    Frame component
    */
    private JFrame _frame;
  
    /**
    *    Tab pane that holds the browser components
    */
    private JTabbedPane _tabs;
  
    /**
    *    Embedded JxBrowser components
    */
    private Browser[] _browsers;
  
  
    /**
    *    Constructs a browser frame
    */
    private BrowserInvoker() {
              
        //    Create the five browser tabs
        _browsers = new Browser[MAX_NUM_TABS];
      
        for(int i = 0; i < MAX_NUM_TABS; i++) {
            _browsers[i] = new Browser();
            _browsers[i].setSilent(true);
            _browsers[i].addDisposeListener(new DisposedListener(i));
        }
    }
  
    /**
    *    Gets the singleton instance
    */
    public static BrowserInvoker getInstance() {
        return _instance;
    }
  
    /**
    *    Builds this UI
    */
    public void buildUI() {
      
        _frame = new JFrame();
        _frame.addWindowListener(new WindowCloseListener());

 


        _tabs = new JTabbedPane();
        _tabs.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
        _frame.getContentPane().add(_tabs, BorderLayout.CENTER);
      
        _frame.setSize(900, 700);
    }
  
   /**
    *    Shows the url(s) in the browser
    */
    public void showBrowser(String title, String[] tabTitles, String[] urls) {
      
        _frame.setTitle(title);
      
        //    Remove any previous tabs
        _tabs.removeAll();
      
        //    Add a new tab for each URL
        for(int i = 0; i < urls.length; i++) {
          
            //    Stop if we've reached the max number of allowed tabs
            if(i == MAX_NUM_TABS) {
                break;
            }
          
            _browsers[i].navigate(urls[i]);
          
            _tabs.addTab(tabTitles[i], _browsers[i]);
        }

 

 

 

        _frame.setVisible(true);
    }
  
 
    /**
    *    Handles closing the window
    */
    class WindowCloseListener extends WindowAdapter {
      
        public void windowClosing(WindowEvent e) {
          
            //    Clear each browser window
            for(Browser browser : _browsers) {
                try {
                    //  Set content to empty to shut down any playing audios/videos
                    browser.setContent("");
                }
                catch(Exception ex) {}
            }
          
            //    Hide this window
            _frame.setVisible(false);
        }
    }
  
    /**
    *    Handles a disposed browser
    */
    class DisposedListener implements DisposeListener {
      
        private int _index;
      
        public DisposedListener(int index) {
            _index = index;
        }
      
        public void browserDisposed(DisposeEvent e) {

 

            //  Not sure if this is the best way, but how else
            //  should I handle disposed browsers? 
            _browsers[_index] = new Browser();
            _browsers[_index].setSilent(true);
            _browsers[_index].addDisposeListener(new DisposedListener(_index));
        }
    }

 

    /**
     *    Used for testing
     */
    public static void main(String[] args) {
           
        BrowserInvoker frame = BrowserInvoker.getInstance();
        frame.buildUI();
       
        String[] title= {"Google", "Yahoo", "Bing"};

        String[] urls = {"http://www.google.com", "http://www.yahoo.com", "http://www.bing.com"};

 

        frame.show("Test", titles, urls);
    }
}

Vladimir Ikryanov TeamDev Ltd. 1,013 posts since
Apr 24, 2006
Currently Being Moderated
1. Feb 8, 2010 2:42 PM in response to: Steve
Re: Main message loop thread is already stopped error in JExplorer

Hi Steve,


According to the stack trace the Browser instance is already disposed when you invoke its navigate method. I'm not sure why it doesn't throw IllegalStateException, but I will try to reproduce this issue and let you know the solution.


Regards,

Vladimir Ikryanov

Scott Torrance   8 posts since
Jul 23, 2009
Currently Being Moderated
2. Aug 17, 2010 6:38 PM in response to: Vladimir Ikryanov
Re: Main message loop thread is already stopped error in JExplorer

I am encountering this error as well. We use JExplorer as an automated testing tool and run many instances in parallel. Under these conditions, we see the error once or twice a day, but it is very hard to reproduce in an individual test case.

When it does occur, it looks like the browser has crashed or closed. I have not found a way to avoid the error or recover from it.

More Like This

  • Retrieving data ...