Asynchronous or Synchronous

C

Clement

Hi....
I am developing a server which needs to do some work for its
client. It may be some calculation that takes some half or one sec.
How should implements.. should i go for ServerSocket with threads or
NIOServers ?

Please help me..

If any related articles there, please let me know...
 
J

John B. Matthews

[...]
I am developing a server which needs to do some work for its client.
It may be some calculation that takes some half or one sec. How
should implement [it]? hould go for ServerSocket with
threads or [ServerSocketChannel]?

[...]

I'm not sure you've supplied enough information to prefer one
approach over the other.

I found this article informative, particularly section nine:

<http://www.cs.brown.edu/courses/cs161/papers/j-nio-ltr.pdf>

Here are some elementary examples:

<http://www.java2s.com/Tutorial/Java/0320__Network/Catalog0320__Network.htm>
 
M

Martin Gregorie

Hi....
I am developing a server which needs to do some work for its
client. It may be some calculation that takes some half or one sec. How
should implements.. should i go for ServerSocket with threads or
NIOServers ?
Just giving the calculation time tells us nothing. We also need to know:
1) the required response time per request
2) how many clients will use the server simultaneously
3) what are the min/average/max request rates per server and in total.
4) is the server handling stateless, i.e. unrelated requests or
does it need to keep a session history for each client?
5) does the server use any shared resources such as a
method that requires locking or a database that it updates?

If you don't know these details which WILL drive the structure of a
heavily used server, then about all you can do is write an unoptimised
first cut version, instrument it to collect statistics for items 1-3 and
release it for production use, see how it performs and be prepared to
rewrite it as needed.

All the performance testing in the world is meaningless if the volumes
and arrival rates don't match what happens in real life.

The server should be designed for change from the outset, not just thrown
together. I'd start with a threaded design that creates a thread for each
incoming connection and kills it when the client disconnects. I'd also
design it with good isolation between the application-specific
calculations and the server management code. Make sure that the
calculation is modular and that each module is instrumented. This way
heavily used and/or resource-intensive modules can be spotted and
replicated more easily.
 
R

Roedy Green

I am developing a server which needs to do some work for its
client. It may be some calculation that takes some half or one sec.
How should implements.. should i go for ServerSocket with threads or
NIOServers ?

Java Concurrency in Practice
http://www.amazon.com/gp/product/03...mp=1789&creative=9325&creativeASIN=0321349601

Discusses the tradeoff. They tend to go for threads on the grounds
coding is simpler and new JVMs can handle much larger numbers of
threads efficiently.
--
Roedy Green Canadian Mind Products
http://mindprod.com
"Humanity is conducting an unintended, uncontrolled, globally pervasive experiment
whose ultimate consequences could be second only to global nuclear war."
~ Environment Canada (The Canadian equivalent of the EPA on global warming)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top