• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need thread syntax  RSS feed

 
Paul Carter
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Currently have code below that plays a series of pictures and sounds and pauses for a set length of time for each sound/image, all from an array currently generated by various methods.

For various reasons this isn't going to work for me, so I want to be able to play a single picture+sound+pause via a thread as my code rolls along without overlap i.e. I want the pauses to complete before any more code is processed on the thread.

I'm guessing that I'll need to create a public thread e.g. 'playThread()' to feed instructions to, but how exactly this should look is currently beyond my very limited Java abilites

Can anyone give me a code snippet that I can spy on?

Many thanks in advance

Paul.


[fbr - added code tags]
[ January 29, 2007: Message edited by: Fred Rosenberger ]
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I liked your wording about a thread "to feed instructions to". That made me think queues. There is a good BlockingQueue in Java 5. Your display thread might do something like this:

Your other "main" thread could put commands into the queue any time it wants. It could put any number of them into the queue and the display thread will pull them out one at a time.

Note that the "command" has a lot of flexibility. It could do nearly anything. If you want this loop to halt as soon as all queued images are done, the main thread could send a command that does nothing but return false.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!