0

我写了 2 个进度监视器,

  • 实现第一次调用时,我在后台收到 ConcurrentModificationException 。但进度监视器我可以看到工作正常,数据也正在加载/更新。

  • 当我在后台得到 ConcurrentModificationException 时实现第二个我也得到 InvocationTargetException 原因是说

    无效的线程访问

请注意,我在第一个进程对话框中使用 Display.getDefault().asyncExec,在第二个对话框中使用 Display.getDefault().syncExec。

请提出这里缺少的内容,因为监视器和数据也根据要求更新/加载,但遗憾的是得到了这个例外。

第一个进度监视器 -

Display.getDefault().asyncExec(new Runnable() {
        public void run() {
            getBroker().stopNotification();
            ProgressMonitorDialog progressMoniorDialog = new ProgressMonitorDialog(
                    Display.getDefault().getActiveShell());
            IRunnableWithProgress runnableWithProgress = new IRunnableWithProgress() {
                @Override
                public void run(final IProgressMonitor monitor)
                        throws InvocationTargetException, InterruptedException {
                    if (mappers.get(profile) != null) {
                        int noOfDGListConfiguratioins = mappers.get(profile).size();
                        monitor.beginTask("Configuration", noOfConfiguratioins);
                        for (final ProfileToDgListViewMapper mapper : mappers.get(profile)) {
                            String sectionName = getCurrentSectionName(mapper);
                            monitor.subTask("Loading contents of section " + sectionName);
                            mapper.mapProfile(profile, list, notification);
                            monitor.worked(1);
                        }
                    }
                    monitor.done();
                }
                private String getCurrentSectionName(ProfileToDgListViewMapper mapper) {
                    String currentSectionName = null;
                    if (mapper instanceof ProfileToDGFileListViewMapper) {
                        currentSectionName = DG_FILE_LIST;
                    } else if (mapper instanceof ProfileToDGPinListViewMapper) {
                        currentSectionName = DG_PIN_LIST;
                    } 
                    return currentSectionName;
                }
            };
            try {
                progressMoniorDialog.run(true, false, runnableWithProgress);
                progressMoniorDialog.close();
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            } catch (InvocationTargetException e) {
                userLogService.logError(Messages.ProfileGroup_ReloadConfiguration_Failed);  
            }
        }
    });

第二个进度监视器 - (加载第一个后在同一个 GUI 上)

Display.getDefault().syncExec(new Runnable() {
            public void run() {
                final DGListFeature dgListFeature = DGListFeature.class.cast(domainModel);
                profile = (PProfile) dgListFeature.eContainer();
                ProgressMonitorDialog progressMoniorDialog = new ProgressMonitorDialog(
                        Display.getDefault().getActiveShell());
                IRunnableWithProgress runnableWithProgress = new IRunnableWithProgress() {
                    @Override
                    public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                        
                                int noOfAssignment = 8;
                                monitor.beginTask("Assign Default Data Labels", noOfAssignment);

                                monitor.subTask(ASSIGN_DEFAULT_DATALABELS + NonP4PProfileReportConstants.DG_FILE_LIST);
                                // 1. Assign default data labels for files
                                assignDefaultDataLabelsForFiles(dgListFeature);
                                monitor.worked(1);

                                monitor.subTask(ASSIGN_DEFAULT_DATALABELS + NonP4PProfileReportConstants.DG_PIN_LIST);
                                // 2. Assign default data labels for Pins
                                assignDefaultDataLabelsForPins(dgListFeature);
                                monitor.worked(1);

                                monitor.subTask(ASSIGN_DEFAULT_DATALABELS + NonP4PProfileReportConstants.DG_KEY_LIST_EF_BASED);
                                ProfileToDgListViewMapperService.getMapperServiceInstance(profile)
                                        .updateDgListConfigurationFeature(profile);
                                monitor.worked(1);

                                monitor.done();
                            }
                };
                try {
                    progressMoniorDialog.run(true, false, runnableWithProgress);
                    progressMoniorDialog.close();
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                } catch (InvocationTargetException e) {
                    userLogService.logError(Messages.ProfileGroup_ReloadDGListConfiguration_Failed);
                }}
        });
4

0 回答 0