Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Multithreaded Rendering  RSS feed

Andy Selador
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to have a task that takes some time (drawing a correctly-sized graph on a BufferedImage using a large series of drawLine() calls). Once this task completes, a JPanel should then use drawImage() to draw the BufferedImage on the screen. I have this all set up using SwingWorker and a PropertyChangeListener ("done" is the important one). The problem is a new SwingWorker subclass (DrawCurveTask) is instantiated and execute()d with every component resize, and the JPanel redraws itself at the completion of every one of these DrawCurveTasks. Does anyone have any ideas on how to make it stop updating itself when the window isn't being resized anymore (i.e. you drag the window all over the place for awhile, stop, and watch the line continuously rerender until all the tasks have executed).

I had tried removing the PropertyChangeListener of all but the newest task, but this meant that it wouldn't redraw with the most recently finished task, and instead would wait for the newest execute()d task to complete. Its kind of a weird problem, so any advice is good.

Also, is there a way to make it work so that a new thread isn't required, but without holding up the paintComponent() method?

Completely unrelated: What are the advantages of using a thread pool? I ask because I just thought of the number of threads that may accumulate (I know SwingWorker sets the limit at 10 running threads, but a more general scenario would be nice).


  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!