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 / General / October 2006

Tip: Looking for answers? Try searching our database.

Threading problem.

Thread view: 
toton - 11 Oct 2006 09:05 GMT
Hi,
 I have a custom control, (extended from JComponent) which also
implements MouseListener and MouseMotionListener & Runnable (or can
have a seperate Runnable implementation also).
Say the run method generates a set of random number (actually it do
something more) and store them  in a GeneralPath member field named
path. It also stores it in another member field named GeneralPath
allPath .
Now what I want when mousePressed event occures it clears the the path
(but not allPath) and starts the thread. The thread in turn adds a
random point on the path. then yield , repaint ,sleep for 5 ms.
when the mosueReleaseed occures, it makes the thread null. Now the
thread to all a point to the path (and allPath) only when  mouse is
pressed. thus I store mousePressed field in a volatile boolean and
check for it before adding.
allPath  purely stores all of the random points , while path to store
random points between a mousePressed & mouseRealeased.
Now, I am experiencing some threading problem . what other
synchronization is needed ? I am doubtfull on mouse realease I make the
thread null, and immediately use mousepress what happens?
Thomas Hawtin - 14 Oct 2006 13:59 GMT
> Now, I am experiencing some threading problem . what other
> synchronization is needed ? I am doubtfull on mouse realease I make the
> thread null, and immediately use mousepress what happens?

I suggest avoiding threading as much as possible. javax.swing.Timer (not
java.util!) is your friend.

Tom Hawtin


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.