0

I have written 2 progress monitors,

  • When implementing first call I am getting ConcurrentModificationException in background. but progress monitor I can see working fine, also data is getting loaded/updated.

  • When implementing second once I am getting ConcurrentModificationException in background Also I am getting InvocationTargetException in cause is is saying

    Invalid Thread Access

Please note that I am using Display.getDefault().asyncExec for first progree dialog and for second one using Display.getDefault().syncExec.

Kindly suggest what is missing here since monitor and data also getting updated/loaded as per requirement but sadly getting this exceptions.

First Progress Monitor -

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);  
            }
        }
    });

Second Progress Monitor - (on same GUI after loading first one)

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);
                }}
        });
James Z
  • 12,209
  • 10
  • 24
  • 44
  • 2
    You use `asyncExec` and `syncExec` in the background threads to run a small bit of UI code in the UI thread - you do **not** use them in the UI thread to run progress monitor dialogs. – greg-449 Dec 10 '21 at 15:26
  • Also you should not call `Thread.currentThread().interrupt();` – greg-449 Dec 10 '21 at 15:28
  • You need to show us a [mre] showing the problem. The code you posted contains many references to other classes so it is impossible to test it. And show use the stack trace for the errors. – greg-449 Dec 10 '21 at 15:35
  • @greg-449 Thank you sir, I have added bunch of code to get some more idea. but next time I will try to have as minimal reproducible. Now I have removed sync, async calls from both monitors, but in second monitor I am facing Caused by: org.eclipse.swt.SWTException: Invalid thread access .... in below code public void setDgLabel(DGLabel newDgLabel) { if (newDgLabel != dgLabel) { NotificationChain msgs = null; msgs = basicSetDgLabel(newDgLabel, msgs); if (msgs != null) msgs.dispatch(); } } – Suraj Dighodkar Dec 10 '21 at 18:26
  • at if (msgs != null) msgs.dispatch(); here it is saying invalid thread acess.... Is it like my current monitor is not able to access this code ?? correct me if i am wrong ... May be I will get some hint here :) Thanks – Suraj Dighodkar Dec 10 '21 at 18:26
  • 1
    You must use Display.asyncExec/synchExec in the monitor code when you want to access UI items - see [this answer](https://stackoverflow.com/a/38844765/2670892) – greg-449 Dec 10 '21 at 18:29

0 Answers0