• Post Reply Bookmark Topic Watch Topic
  • New Topic

Confused by threads.

 
Al Hollis
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a thread running which is doing some animation of a image. I then tried to set up another thread so i could have a delay before another function runs which doesnt interefere with the first step. I think im getting confused with how threads work. The animation thread is set up in a class called reel. And the other thread is set up in a class called threadController. However this thread runs before the thread in the animator runs even though in the code the animator is told to start running before the other thread.

E.g

This code is called first. Inside startspin the animation thread for each object is run. (So three threads in total)


The next stage is to check for a win



This thread needs to cause a delay to give the reels a time to actually be seen spinning. But this new object is interefering with the first three threads even though its called at a later point!!
[ May 09, 2006: Message edited by: Al Hollis ]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without seeing lots more code (and I really don't want to see it ) I can't tell for sure what's up, but this line makes me suspicous:

keepSpinning.run();

If threadControl is a subclass of Thread, then this is the wrong way to start it. The method run() (which you may override) is just a plain old ordinary method, and if you call it, then it executes and runs to completion before returning, just like any other method.

Thread.start(), on the other hand, is full of magic and mystery. It arranges, though some black art to which we mere mortals are not privy, to create a new parallel thread of execution, and on that new separate asynchronous thread, run() will be called. start() returns immediately, but after it returns, run() will be running in parallel.

You're going to need to send messages between your threads and coordinate their activities, and this requires some initiation into the black arts. You may acquire the needed knowledge here. Take your time, read carefully, do the exercises.
 
Al Hollis
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
haha Thank you for your help. I shall look into these black arts
 
Al Hollis
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the link. Solved my problem using a swing timer Reels are working wonderfully now
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!