Re: Help in Multi threading!
Sundar wrote:
Hi,
There are three threads in the player.
1) Master Thread
2) Buffer Thread
3) Play Thread
The master thread should control the other two threads. So Master
thread should
communicate to the Bufffer thread and wait for a response. As soon as
it gets the
response from the Buffer Thread, the master thread should communicate
to the Play thread.
After playing the data, the play thread should send back a message to
the master thread.
Till this message is recieved the master thread should wait.
Patricia Shanahan wrote:
... look at java.util.concurrent, especially the blocking queues.
They seem ideal for the message passing model of thread communication,
and you expressed your problem in terms of message passing.
If your algorithm is completely synchronous, how will threads help you?
public void play( String audioFile, int blockSize ) // untested
{
FileChannel fc = new FileInputStream( audioFile ).getChannel();
for ( ByteBuffer buffer = ByteBuffer.allocate( blockSize );
fc.read( buffer ) >= 0L; buffer.clear() )
{
buffer.flip();
play( buffer );
}
}
- Lew
- Lew