Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8118245

Gtk: FileChooser consumes CPU resources when selecting many files

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Not an Issue
    • Affects Version/s: 7u40
    • Fix Version/s: 8
    • Component/s: javafx
    • Labels:
    • Environment:

      java version "1.7.0_12-ea"
      Java(TM) SE Runtime Environment (build 1.7.0_12-ea-b07)
      Java HotSpot(TM) 64-Bit Server VM (build 24.0-b28, mixed mode)

      Ubuntu / KDE

      Description

      The JavaFX FileChooser doesn't work well when multiselecting many files (say, 100).

      Sample code:


      import java.io.File;
      import java.util.List;
      import javafx.application.Application;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.scene.Group;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.TextArea;
      import javafx.scene.control.TextAreaBuilder;
      import javafx.scene.layout.VBox;
      import javafx.scene.layout.VBoxBuilder;
      import javafx.stage.FileChooser;
      import javafx.stage.Stage;

      public class Bug extends Application
      {
          public static void main(String[] args)
          {
              launch(args);
          }

          @Override
          public void start(final Stage primaryStage)
          {
              primaryStage.setTitle("bug");
              Group root = new Group();

              final TextArea textArea = TextAreaBuilder.create().prefWidth(400).wrapText(true).build();

              Button buttonLoad = new Button("open files");
              buttonLoad.setOnAction(new EventHandler<ActionEvent>()
              {

                  @Override
                  public void handle(ActionEvent arg0)
                  {
                      FileChooser fileChooser = new FileChooser();

                      // Show save file dialog
                      List<File> files = fileChooser.showOpenMultipleDialog(primaryStage);
                      System.out.println(files.size());
                      textArea.setText("Ok, done - " + files.size());
                      System.out.println("setText call finished");
                  }
              });

              VBox vBox = VBoxBuilder.create().children(buttonLoad, textArea).build();

              root.getChildren().add(vBox);
              primaryStage.setScene(new Scene(root, 500, 400));
              primaryStage.show();
          }
      }

      So, if you click the button to display the file chooser, it comes up as expected. Multiselect many files (say, about 100).
      You will the "System.out.println(files.size());" print to the console immediately after you click ok on the file chooser.
      At this point, the file chooser should be hidden - it has already handed us the file list.

      However, what I observe is the file chooser stays on the screen for about 10 seconds. CPU Usage goes to 100%, and the entire JavaFX app stops repainting.

      About 10 seconds later, the file chooser finally goes away, and the FX app starts repainting per normal.

      I have been unable to determine what on earth the FX thread is doing during these 10 seconds.

        Attachments

          Activity

            People

            Assignee:
            azvegint Alexander Zvegintsev
            Reporter:
            vortexjfx vortex (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported: