I have a fairly large java application which is partly made up of a
whiteboard which you can use a freehand tool to draw on. Currently it
works by simply listening to mouse movements and recording each point
etc.
This works fine unless some other thread is already going when
theyuser tries to start drawing or decideds to run (even at a low
priority) when freehand drawing is in place. I CANNOT afford even a
small delay in handeling user drawing as mouse movement is lost and
the lines drawn look funny.
So basically as soon as the user starts drawing (mouse down) I want
to lock all other threads so I am only catching mouse movements (even
if I have to get the AWTEvent from the EventQueue directly) and call
paint on the graphics object to update the screen for that line
segment. Then when the uses stops drawing the line (mouse up),
reenable all the other threads.
However, given I don't have control over some of the other threads
codebase (some are written by others and some core to java -- like gc)
the only way I could come up with was to enumerate all the threads
(get the highest ThreadGroup parent) and suspend() all those that are
not me. However, this could possible cause a deadlock.
Anyone have any other ideas about how to fix this?
Thanks,
Preston
Roedy Green - 31 Jul 2003 06:24 GMT
>Anyone have any other ideas about how to fix this?
You could also temporarily push the other threads to the lowest
possible priority.
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
PT - 31 Jul 2003 18:51 GMT
> >Anyone have any other ideas about how to fix this?
>
> You could also temporarily push the other threads to the lowest
> possible priority.
The problem here is that the actual drawing is not that resource
intensive so even lower priority threads will run. Rather the
operation is simply very time sensitive so if the threads are running
at the wrong few milliseconds things don't look right.
William Brogden - 31 Jul 2003 19:48 GMT
> I have a fairly large java application which is partly made up of a
> whiteboard which you can use a freehand tool to draw on. Currently it
[quoted text clipped - 11 lines]
> segment. Then when the uses stops drawing the line (mouse up),
> reenable all the other threads.
I always found that the mouse can generate events much faster than
paint can keep up. It may pay to drop events that are very close together
if painting is behind.
> However, given I don't have control over some of the other threads
> codebase (some are written by others and some core to java -- like gc)
[quoted text clipped - 6 lines]
> Thanks,
> Preston