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.
I am currently working on a HTTP based chat server .In my server I have a single servlet which gets commands from clients , to process those commands I have used command pattern .Since there could be any no of clients connected to my server at a time say 1-10000 I don�t want my servlet to process each request for performance issues. what I do in servlet that I make a command object as soon as I get a command from client and store it to a queue (LinkedListBlockingQueue).Using this technique my servlet is basically receiving requests and storing them to a queue which obviously is a lighter task as compared to the process in whihc servlet had to accept and process each request. Now the thread(s) listening to the queue (LinkedListBlockingQueue) will be notified as soon as a command is stored in the queue and it will get all those commands from queue and execute them one by one. I just need your suggestion that is it a good design strategy or I should accept and process requests in the same servlet?
Waiting for your kind reply Sajjad Ahmed Paracha [ August 21, 2007: Message edited by: Bear Bibeault ]
JEE and containers in particular take care of most of these issues for you. Trying to implement it yourself, particularly when you aren't sure whether it is required or not, is more likely to make things worse than better.
Just my opinion, but not something I'd try.
Joined: Jan 23, 2003
Dear David O'Meara ! Thanks for your quick reply , i am affraid i couldnt understand your point here can you please describe it furthur more.
Each request to the server is executed in a separate thread. I am not sure if your scenario calls for the use of the command or observer patterns. Are you experiencing high CPU times when so many clients are accessing your application ? There might be other bottle necks
Containers manage thread pools to improve running of multiple tasks and depending on the server you are using you may have access to worker and queue threads which already provide handling of high volume periods.
Trying to implement something that already exists may cause problems and worse you may get it wrong.
Joined: Jan 23, 2003
In case of a Chat server implementation we have to make sure that if a client (say email@example.com) is sending chat messages to another client(say firstname.lastname@example.org) those messages should be sent to the other client(email@example.com) in the same order in which our client (firstname.lastname@example.org) sent. say client a sent following 10 messages to client b , from it's chat window a says : 1 2 3 4 5 6 7 8 9 10
client b must also see the messages in the same order , as sending messages without the order wil not make sense to b. Now if i use the server implementation of managing requests in seprate Threads there might be a possibilty that thread having message 9 executes before thread having messages 8 which will result that disorder in messages and b will see those disordered messages.might be like this
a says : 1 3 2 4 5 8 7 6 10 9
so in order to send b message in exectly the same order we need to first queue all those messages (command objects) in a FILO queue and then send them to b in same order. so i guess for this case we cant rely on the server's implementation of request processing. so what do you think?