dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


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

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


Object passing between threads

Question:
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.

Answer:
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.

 

 

Sitemap
×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date