Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Virtual Machine / July 2003

Tip: Looking for answers? Try searching our database.

Complete threading control for drawing app

Thread view: 
PT - 30 Jul 2003 23:57 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
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.