Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Java Language
Expertise: Beginner
May 31, 1998



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Object passing between threads

Am implementing a network simulation program that requires a sender and receiver thread, with a frame object being passed between the two threads. Could you suggest a way of connecting the threads by means of an object stream that would allow the object to be passed between the two threads. What is required is much like the pipe implementation in c except from what I gather in java the data types that can be sent are limited.

If you feel the best way to implement your simulation is by using streams, you will want to look at java.io.PipedInputStream and java.io.PipedOutputStream. These allow you to read and write data between two threads. All you have to do is wrap them with ObjectInputStream and ObjectOutputStream and also make your network frame object implement the Serializable interface, so that it may be written to an ObjectInputStream.

There may be alternative ways to implement your simulation by using explicit synchronization and variable assignments rather than using streams to simulate the sending and receiving of frames.

DevX Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date