JavaFX application with an ImageIO call on a thread other than JavaFX Application Thread hangs on Mac OS X

前端 未结 2 1017
伪装坚强ぢ
伪装坚强ぢ 2021-01-27 10:09

Consider I have a sample JavaFX application which updates its UI with an image read from the application\'s JAR, and does so in a delayed manner (i.e. the image is pain

相关标签:
2条回答
  • 2021-01-27 10:53

    I'm writing an application that needs to lazy-load image thumbnails on a separate thread. ImageIO.read() was hanging, too. But someone suggested doing

    new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
    

    in the main application thread before starting other threads, as this apparently causes AWT to run some initialization code the first time which has to be done in the main thread. That solved the ImageIO.read problem.

    But it was also hanging when calling

    SwingFXUtils.toFXImage(bufferedImage, null);
    

    so I moved that inside my "Platform.runLater(...)" call so that it would be done on the JavaFX thread, and that worked, though it isn't ideal, since I would like that conversion to happen on the separate thread so the UI will be more responsive. But that conversion happens in memory, so I can live with it.

    0 讨论(0)
  • 2021-01-27 11:07

    The above behaviour seems to be a bug in the Mac OS X implementation of Oracle JDK -- the problem shows up only with Java 1.8.0, I was unable to reproduce it against either Java 9.0.4 or 10.0.2.

    0 讨论(0)
提交回复
热议问题