This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
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
Consider Paul's rocket mass heater.
subject: Collection Class on a Network