Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Correct use of threads?  RSS feed

 
Eoin Mac Aoidh
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am inexperienced with the use of threads, and I just wanted some advice as to whether I should use threads or not in the following situation:

My application records the position of the mouse every time it is moved on the interface.
Each time the MouseMoved method is called, I note the co-ordinates of the mouse, get the currentTimeMillis(), a couple of other things, and do some calculations.
The more things I do at this stage, (ie. the more code to be executed in the mouseMoved method) the less often the mouse position is recorded; thus I have less data to work with.

Basically I want the mouseMoved method to run as quickly as possible, so I capture as many mouse positions as possible.

Would it be a good idea, (or possible even!!?) to capture the mouse co-ordinates with one thread while another concurrently gets the time, and another carries out the computation based on the information captured by the other two threads?
-Is it possible to pass values from one thread to another?

Any thoughs on this would be greatly appreciated,
Thanks in advance,

Eoin.
[ February 23, 2007: Message edited by: Eoin Mac Aoidh ]
 
Henry Wong
author
Sheriff
Posts: 22842
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would it be a good idea, (or possible even!!?) to capture the mouse co-ordinates with one thread while another concurrently gets the time, and another carries out the computation based on the information captured by the other two threads?


To have a separate thread get the system time, is a bad idea. That operation is so fast, it should be done by the event dispatching (mouse) thread. Just have the mouse event store the coordinates along with the time, in some sort of queue for processing by another thread.

As for having another thread do the computation, it would depend on the computation. If it *really* takes a long time, then it may be worth it to have a separate thread. It takes time to start another thread, or to dispatch the work to another thread, so it would be silly to do it for really fast computations.

What is deemed fast? What is *really* takes a long time? I am not sure. There is a huge gray area where you can't be sure until you try it.

Henry
 
Eoin Mac Aoidh
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just have the mouse event store the coordinates along with the time, in some sort of queue for processing by another thread.

Thank you Henry - That is very helpful advice. I will give it a try.
Much appreciated.

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