小编Seb*_*ies的帖子

在后台更新JavaFX树时出现ConcurrentModificationException

我的代码TreeItem<String> 在后台任务中创建,因为我有很多它们,并且它们的创建需要相当长的时间才能冻结应用程序.在这个例子中它没有多大意义,但它说明了我在实际应用程序中遇到的问题.扩展节点时,程序会抛出ConcurrentModificationException.

我使用jdk1.7.0_17和JavaFX 2.2.7

有谁知道如何创建线程安全Tree或如何规避问题?

例外

java.util.ConcurrentModificationException
    at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:819)
    at java.util.ArrayList$Itr.next(ArrayList.java:791)
    at com.sun.javafx.collections.ObservableListWrapper$ObservableListIterator.next(ObservableListWrapper.java:681)
    at javafx.scene.control.TreeItem.updateExpandedDescendentCount(TreeItem.java:788)
    ...
Run Code Online (Sandbox Code Playgroud)

import javafx.application.Application;
import javafx.collections.ObservableList;
import javafx.concurrent.Task;
import javafx.scene.Scene;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

import java.security.SecureRandom;
import java.util.Random;


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

    @Override
    public void start(Stage stage) throws Exception {
        TreeView<String> treeView = new TreeView<String>(createNode("root"));
        HBox hBox = new HBox();
        hBox.getChildren().addAll(treeView);
        Scene scene = new Scene(hBox);
        stage.setScene(scene);
        stage.show(); …
Run Code Online (Sandbox Code Playgroud)

java javafx-2

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

java ×1

javafx-2 ×1