package greenfoot.sound;

import java.util.LinkedList;


| A thread to process certain sound commands, which for some reason | must be processed in a separate thread. | | @author Davin McCall | public class ClipProcessThread implements Runnable{ private Thread thread; private LinkedList<SoundClip> queue = new LinkedList<SoundClip>(); public ClipProcessThread() { thread = new Thread(this); thread.setDaemon(true); thread.start(); } public void addToQueue(SoundClip clip) { synchronized (queue) { queue.add(clip); queue.notify(); if (! thread.isAlive()) { thread = new Thread(this); thread.setDaemon(true); thread.start(); } } } @Override public void run() { try { SoundClip item; while (true){ synchronized (queue) { while (queue.isEmpty()){ queue.wait(); } item = queue.removeFirst(); } item.processState(); } } catch (InterruptedException ie) { } } }
top, use, map, class ClipProcessThread

.   ClipProcessThread
.   addToQueue
.   run




67 neLoCode + 3 LoComm