-
Notifications
You must be signed in to change notification settings - Fork 978
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Use SwingWorker to read GCModel in a background thread #87
Comments
I should add, that we must code thread-safe in the code used by readModel. |
Hi Hans, I like your idea of using threads to load the files! The blocking of the I am not much into multi threading recently, so my questions might show
Looking into the code, I have a small wish list:
What do you think? Best regards, Jörg PS: Why the Google+ account? |
I do not have much GUI/Swing experience, so I guess we complement each other.
Google+ account? Maybe better for discussions. Maybe, with some more refactoring, the GCModelLoader can be the creator of the ChartPanelView. i.e. Launch the ChartPanelView from GCModelLoader.done(). Also saves some clean-up work if loading the model fails. |
Hi Hans, Thank you for the explanations! Now I understand better, why the I believe, that refactoring the inner classes into their own classes It sounds like a good idea to me, to launch the ChartPanelView from Do you know about the mailing list Best regards, Jörg |
I've removed the ThreadGroup, ThreadFactory and ShutdownHandler and it still works fine. SwingWorker.execute() does a good job installing using its own shutdown handler. I do not have time, yet, to extract the GCModelLoader from ChartPanelView. |
Hi Jörg, I've missed your comment, while I was busy with my next build, commit, push and the comment about it. Warnings by the parser, you mean? On the mailing list: I know and I already have the RSS feed in my RSS reader (Liferea). Best regards, Hans |
I broke the export function, because I forgot to setUrl on the GCModel. |
Hi Hans, You did quite some work again, thank you! Extraction of GCModelLoader from ChartPanelViewMight be difficult, because I think it is in an area that is not well Warnings by the parser not shown. Suggestion to add them to the GCModel.I fear, that I didn't understand your suggestion when I first read it. I'll need a few days until I'll be able to look into your code and test it. Best regards, Jörg |
The problem I had with the original static parser, was that messages for all concurrently loading files were displayed in all textAreas. |
Ok, I see. That's part of what wasn't thread safe. |
My first attempt to load the model before creating a ChartPanelView: Added to GCDocument: List<GCModelLoader> modelLoaders;
public void add(final URL url) {
final GCModelLoader modelLoader = new GCModelLoader(this, url);
modelLoaders.add(modelLoader);
modelLoader.execute();
}
public void gcModelLoaderDone(final GCModelLoader modelLoader, final GCModel model) {
modelLoaders.remove(modelLoader);
if (model != null) {
createChartPanelView(model);
gcViewer.repaint();
repaint();
}
}
protected void createChartPanelView(final GCModel model) {
//In the ChartPanelView constructor I've replaced URL with GCModel (which contains URL).
final ChartPanelView chartPanelView = new ChartPanelView(this, model);
chartPanelViews.add(chartPanelView);
.....
//... remainder of the original add(URL) method ...
} In other words:
This works fine, but I do not have any error handling nor any progress indicator. GCDocument.add(url)
GCDocument.reloadModels(boolean) // called from Refresh.actionPerformed() do not make sense, anymore. And I do not know where/how to implement reloadModel, yet. The easiest would be to just create a new ChartPanelView with the new model and replace the old one. But maybe it's better to reload the data into the existing ChartPanelView. |
Hmm, maybe modelLoaders is not needed at all. I added it, because I expected it needed to be maintained, somehow. Well, maybe when GCDocument is closed. |
I've added a GCModelLoaderView, which contains:
It shows either the JProgressBar or the error message, depending on the result. Still some issues:
I'd prefer to pass the new GCResource to the DataReader implementation, but then a lot of code has to be modified.
|
Indeed, first I had the idea of creating a GCModel in the GCModelLoader, pass it to the reader and get it back.
|
A tab in ChartPanelView might be a good solution for reloading. In my latest implementation ChartPanelView is only created after loading+parsing has completed successfully. |
GCResource seems to be a sensible unit. Thank you for explaining the details. Ah, I see! You open a GCDocument and show the GCModelLoaderView inside. Upon successful completion you replace it with a ChartPanelView. My Idea was close to yours: I wanted to open the GCDocument only after completion of parsing. To display the progress, I wanted to introduce one JDialog (non modal window; always on top) showing all models currently being loaded in the background. As soon as one would be finished, the appropriate GCDocument would be opened or updated (responsibility of GCViewerGui; GCModelLoaderController just informs GCViewerGui about completion). My idea to handle complete failures in its own popup window (as today) is indeed not a good idea. I don't like many dialog boxes opening swiftly. I like your approach better using a GCDocument to display the parser messages. Opening several files at once works nice with your implementation! I think, I'll have to try a bit more with my Controller class and maybe the JDialog. |
Hi Hans I have tried to add my controller this weekend. I ran into a problem however: Often the chart is not drawn after loading of the file (mostly if the file is passed as a command line parameter, but also in other cases). Do you also experience this behaviour? I tested with your latest commit. The second last commit does not have this symptom. Regards, Jörg |
Hi Jörg, Maybe yours is a different issue, but when I experienced something similar, I first found that it also failed in the 1.33 version and then I found that my settings were changed: all checkboxes in the "View" menu were blank, so I only got the chart without any data in it. No idea, what caused this. Hans |
Hi Hans, It is the checkboxes unchecked in my case as well. Not as robust as I'd like it to be :-/. I can't reproduce it with 1.33. Can you give me the steps on how to reproduce it? Regards, Jörg |
I did not create the issue with 1.33. Only after I had it with my latest build, I tried 1.33 and it also happened. |
Apparently somehow the |
From GCViewerGui.internalFrameActivated(): menuItemFullGCLines.setState(getSelectedGCDocument().getModelChart().isShowFullGCLines());
menuItemIncGCLines.setState(getSelectedGCDocument().getModelChart().isShowIncGCLines());
.......
menuItemAntiAlias.setSelected(getSelectedGCDocument().getModelChart().isAntiAlias()); From ModelChartImpl: public boolean isShowFullGCLines() {
return fullGCLineRenderer.isVisible();
} So GCViewerGui.internalFrameActivated() is called, while the chart (and fullGCLineRenderer) is not visible, yet. |
Hi Hans, Thank you for tracking this down! I've come to the same conclusion. By the way: I don't suspect you to have introduced this bug. I believe that a bad decision I made earlier led to this behaviour. I didn't program it to be robust. But I still can't reproduce it using 1.33. If you can I'd be grateful to know how. Because then I'd like to fix this as soon as possible for 1.33. Regards, Jörg |
I think I have seen the same problem with an older Version before (very sporadic). So I guess its a race. Bernd
|
@ecki thank you for confirming the bug with the white chart. I have pushed a fix to #87-swingworker branch. The white charts should not occur any more. As a next step I'll try to refactor GCViewer towards the MVC pattern. Currently the views often are also the controller and sometimes contain model elements. I suspect, this makes the addition of some features here very difficult (like reloading of the model). Regards, Jörg |
Hi Hans, Sorry for taking so long! I have had little time in the last few months and found some issue with my refactoring that took me quite some time to get fixed. I have pushed another branch to my repository (#87-swingworker-fixed) where I fixed that issue I had with the refactoring in the #87-swingworker branch (which I now deleted). I believe, I have been able to go a step towards the MVC pattern in the gui layer, allthough not the whole way yet. I think, I have add most of the suggestions you had not added yet. The most obvious feature missing yet is the possibility to interrupt a thread loading a gc file, if it takes too long. Best regards, |
I have renamed the branch to feature/#87/swingworker. |
* develop: reduce number of WARNING messages when parsing introduction of a detailed G1 message fails (#128) add Àngel Ollé Blázquez to list of contributors fix merge problem between #129 and #130 export graph to PNG fature using the GCViewer GUI Command line graph generation random issue parallel scavenge collector: handle combination of -XX:+PrintAdaptiveSizePolicy, -XX:+PrintTenuringDistribution, -XX:+PrintApplicationStoppedTime (#128) fix negative pause for VM_OPERATION event near parser problem (#128) Conflicts: src/main/java/com/tagtraum/perf/gcviewer/exp/impl/DataWriterFactory.java src/main/java/com/tagtraum/perf/gcviewer/view/SimpleChartRenderer.java src/test/java/com/tagtraum/perf/gcviewer/imp/TestDataReaderSun1_7_0G1.java src/test/java/com/tagtraum/perf/gcviewer/imp/TestDataReaderSun1_8_0G1.java
Conflicts: src/test/java/com/tagtraum/perf/gcviewer/imp/TestDataReaderSun1_6_0.java src/test/java/com/tagtraum/perf/gcviewer/imp/TestDataReaderSun1_8_0.java
Conflicts: pom.xml src/main/java/com/tagtraum/perf/gcviewer/view/ScreenCenteredDialog.java src/main/java/com/tagtraum/perf/gcviewer/view/SimpleChartRenderer.java
# Conflicts: # .travis.yml # src/main/java/com/tagtraum/perf/gcviewer/imp/AbstractDataReaderSun.java # src/main/java/com/tagtraum/perf/gcviewer/imp/DataReaderFacade.java # src/main/java/com/tagtraum/perf/gcviewer/imp/DataReaderFactory.java # src/main/java/com/tagtraum/perf/gcviewer/imp/DataReaderSun1_6_0.java # src/main/java/com/tagtraum/perf/gcviewer/imp/DataReaderSun1_6_0G1.java # src/main/resources/localStrings_fr.properties # src/test/java/com/tagtraum/perf/gcviewer/TestAll.java # src/test/java/com/tagtraum/perf/gcviewer/imp/TestAllImp.java # src/test/java/com/tagtraum/perf/gcviewer/util/TestLocalisationHelper.java
# Conflicts: # src/main/java/com/tagtraum/perf/gcviewer/ctrl/action/OpenFile.java # src/main/java/com/tagtraum/perf/gcviewer/view/AboutDialog.java
I have now merged the branch into "develop" and close this issue. |
In the current 1.33 implementation the Swing event dispatcher thread is blocked during loading the GCModel. It means that you cannot select anything in the menu, you cannot even quit the application.
I've created a fix in https://github.com/hbswn/GCViewer
It's not production ready, but for developers it's nice to play with.
I added:
Some issues:
Let me know, what you think.
(maybe I should create a Google+ account)
The text was updated successfully, but these errors were encountered: