This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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.
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.