Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / November 2006

Tip: Looking for answers? Try searching our database.

Help in Multi threading!

Thread view: 
Sundar - 10 Nov 2006 13:42 GMT
Hi,

Iam working on creating an audio player applet.

I face some difficulties in multithreading in java. The problem i need
to solve is
explained below,

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.

So the question i have is "How to communicate between threads? How can
we make a thread
wait for other threads response?"

sample code, link Or help in any form is highly appreciated.

Thanks in advance
-Sundar
Patricia Shanahan - 10 Nov 2006 15:16 GMT
> Hi,
>
[quoted text clipped - 27 lines]
> Thanks in advance
> -Sundar

Does it have to run on pre-1.5 versions of Java?

If not, 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.

Patricia
Lew - 11 Nov 2006 19:20 GMT
>> Hi,
>> There are three threads in the player.
[quoted text clipped - 11 lines]
>> the master thread.
>> Till this message is recieved the master thread should wait.

> ... 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
ANONYMOUS.COWARD0xC0DE@gmail.com - 11 Nov 2006 06:07 GMT
> Hi,
>
[quoted text clipped - 27 lines]
> Thanks in advance
> -Sundar

java.io.PipedInputStream
java.io.PipedOutputStream

explicit data passing between threads.

or you can use synchronized blocks of code in each thread and use wait
and notify to set variables at appropriate times.
Sundar - 11 Nov 2006 06:41 GMT
Thanks for your help.

I took a look into wait() and notify() mothods. Im got stuck and i
could not find a way to use wait and notify. Is there any code snippets
availabe which gives the example of wait and notify methods??

Thanks in advance

-Sundar

> > Hi,
> >
[quoted text clipped - 35 lines]
> or you can use synchronized blocks of code in each thread and use wait
> and notify to set variables at appropriate times.
Gordon Beaton - 11 Nov 2006 08:51 GMT
> java.io.PipedInputStream
> java.io.PipedOutputStream
>
> explicit data passing between threads.

That's just silly. There's no need to *stream* data between threads
when you can pass object references or simply call methods in the
target thread.

/gordon

Signature

[ don't email me support questions or followups ]
g o r d o n  +  n e w s  @  b a l d e r 1 3 . s e



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.