File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Sockets and Internet Protocols and the fly likes Collection Class on a Network Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Collection Class on a Network" Watch "Collection Class on a Network" New topic

Collection Class on a Network

Jack Sampson

Joined: May 08, 2008
Posts: 2
Hi guys, not sure if this should be in the I/O section or here, but here's my problem.

I've created a multithreaded simulation of a producer consumer pattern using a linked blockingqueue, as shown in the javadocs for blockingqueue. It works by having one class with multiple threads each executing a method to add a string to a blockingqueue, another class acting as the blockingqueue and the main method and another class which has threads that take the next string from the queue and prints the contents of that string.

I'd like to have this working over a network, with each class on a separate machine and I was thinking I could have a client that produces the string and writes it to the socket of a server. The server collects all the strings and another client on another machine acts as the consumer and takes from the collection.

I know how to create basic multithreaded servers clients, I'm just stuck with keeping the strings in the correct order and how to take from the queue on the consumer end. Will a buffered input and output stream be sufficient to keep concurrency / synchronization?

Any suggestions of how to accomplish this would be appreciated.

Satya Maheshwari
Ranch Hand

Joined: Jan 01, 2007
Posts: 368
I think if you are doing this over a TCP socket, it would be taken care of since it maintains the packet ordering. And since you are already taking care of the ordering in you not n/w based blocking queue, it should work fine.

Thanks and Regards
I agree. Here's the link:
subject: Collection Class on a Network
It's not a secret anymore!