Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala 是否有机会获得-飞溅:<;图像>;适用于需要-XstartOnFirstThread的SWT应用程序?_Scala_Swt_Java 7_Java 6_Splash Screen - Fatal编程技术网

Scala 是否有机会获得-飞溅:<;图像>;适用于需要-XstartOnFirstThread的SWT应用程序?

Scala 是否有机会获得-飞溅:<;图像>;适用于需要-XstartOnFirstThread的SWT应用程序?,scala,swt,java-7,java-6,splash-screen,Scala,Swt,Java 7,Java 6,Splash Screen,我使用以下方式启动Scala SWT应用程序: java-splash:splash.jpg-jar-application.jar 在Mac OS X 10.9.1上使用JDK 1.6.0,启动屏幕立即打开(在实际应用程序窗口打开前几秒钟) 当SWT应用程序窗口打开时,我使用以下代码关闭启动屏幕: // When the window opens for the first time close the splash screen if exists val splash = SplashSc

我使用以下方式启动Scala SWT应用程序:

java-splash:splash.jpg-jar-application.jar

在Mac OS X 10.9.1上使用JDK 1.6.0,启动屏幕立即打开(在实际应用程序窗口打开前几秒钟)

当SWT应用程序窗口打开时,我使用以下代码关闭启动屏幕:

// When the window opens for the first time close the splash screen if exists
val splash = SplashScreen.getSplashScreen
if (splash != null) {
  shell.addShellListener(new ShellAdapter {
    override def shellActivated(event: ShellEvent) {
      shell.removeShellListener(this)
      splash.close
    }
  })
}
该行为符合预期: 我得到了一个很早的启动屏幕,当应用程序准备好时,它就关闭了

现在,在JDK 1.7.045上,当应用程序窗口打开且应用程序冻结在
splash.close时,启动屏幕即打开

我了解到,从Java6到Java7对SplashScreen的
API进行了一些更改,但这并不能解释完全不同的行为

在Java7上运行SWT应用程序的JVM启动屏幕是否有变化


仅供参考:我使用的是没有Eclipse的普通SWT(包括支持闪屏的Eclipse启动器)。

也许JDK9或更高版本中会有解决方案。目前,在OS X Yosemite上使用JDK8并没有改善这个问题

目前,我将使用此代码段或此代码段中的代码。他们两个都在工作


希望这个bug能在JDK9中关闭

终于找到了答案!因为飞溅也是在第一个线程上创建的,所以我们需要进行一些消息处理,这可以通过在主线程上运行SWT事件循环来实现

在运行时,您可以与启动屏幕交互,而无需冻结应用程序中其他线程

我将所有对SplashScreen处理内容的调用(以及对其进行渲染和取消渲染)包装在可运行文件中,并传递给此函数:

private static void executeSafeForMac( Runnable r ) {
    // On non Mac systems no problem
    if( System.getProperty("os.name").toLowerCase().indexOf("mac")<0 ) {
        r.run();
        return;
    }

    // On Mac we must be moar intelligent
    Display display = Display.getDefault();
    final Semaphore sem = new Semaphore(0);
    Thread t = new Thread( ()->{
        r.run();
        sem.release(); // Can be anything.
        display.asyncExec(()->{}); // Ensure the Event loop has one last thing to do
    }, "SplashScreenInteractor" );
    t.start();

    // Okay, we do SWT event loop stuff to make the SplashScreen responsible until the  
    // SplashScreen stuff doing Runnable has been done and the semaphore is released.
    while( !display.isDisposed() && !sem.tryAcquire() ) {
        if( !display.readAndDispatch() ) {
            display.sleep();
        }
    }

}
private static void executeSafeForMac(可运行r){
//在非Mac系统上没有问题
if(System.getProperty(“os.name”).toLowerCase().indexOf(“mac”){
r、 run();
sem.release();//可以是任何内容。
display.asynceec(()->{});//确保事件循环还有最后一件事要做
}“互动者”);
t、 start();
//好的,我们做SWT事件循环的东西,让SplashScreen负责直到
//SplashScreen做Runnable的工作已经完成,信号量已经释放。
而(!display.isDisposed()&&!sem.tryAcquire()){
如果(!display.readAndDispatch()){
display.sleep();
}
}
}

如果不调用splash.close会发生什么情况?当显示第一个窗口时,启动屏幕应该自动关闭。它不会关闭,因为我没有打开Swing/AWT窗口。SWT窗口不会触发自动关闭。在我看来,JVM参数
-splash
不能与Cocoa上的SWT所需的
-XstartOnFirstThread
组合。当我使用ommit
-xstartonfirsthread
时,启动屏幕工作,但SWT应用程序不工作。其他人也遇到了同样的问题:OpenJDK bug跟踪器中的相应问题: