• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Multithreaded Rendering

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).

Thanks,

Andy
 
eat bricks! HA! And here's another one! And a tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic