Invalid Thread Access even with XstartOnFirstThread in vm args

后端 未结 2 1363
故里飘歌
故里飘歌 2021-01-06 06:53

I have an embryonic Java Web Start application with a single class. It runs on Windows and Linux but gets the dreaded Invalid Thread Access error on Mac OS X. I realise that

2条回答
  •  时光说笑
    2021-01-06 07:03

    Clearly, your main method is not being executed on the main thread. You can see in the stack trace that the launcher is actually started in another thread, and then the Launcher only indirectly calls main. This is unfortunately just the diagnostic, I am not sure about the solution. I have done a similar thing (SWT app through Java Web Start), but I can't remember how we solved this, if at all.

    After checking the com.sun.javaws.Launcher source code, it is quite unclear how this could be made to work. The Launcher.launch method starts a new thread within which your main method is executed. You can follow the code to recreate the exact stacktrace you are getting.

    The main entry point of Java Web Start shows that the main thread dies soon after starting.

    Update

    I dug something out: in this Eclipse bug report it is suggested that the problem could be related to this:

    
      
      
    
    

    The parser takes the j2se spec from here and ignores the later, more specific ones. Try removing the line.

    Update 2

    Now I dug this up from here:

    com.apple.concurrent.Dispatch.getInstance().getNonBlockingMainQueueExecutor().execute(
      new Runnable() { public void run() {
          final Display display = Display.getDefault(); 
          while (!display.isDisposed()) {
            if (!display.readAndDispatch())
              display.sleep();
          }
    });
    

    This actually sounds like something workable. It does exactly what I described in my comment below: patches into the main thread through a mechanism specifically put in place for this purpose. Try to adapt this to your need. You may not even need -XstartOnFirstThread with this.

    Update 3

    I finally found my old SWT-JWS project. It's got this in it:

    
      
      
    
    

    and it works. It has no default j2se element, this element appears only in the OSX-specific entry.

提交回复
热议问题