Asynchronous or Synchronous

Discussion in 'Java' started by Clement, Nov 25, 2008.

  1. Clement

    Clement Guest

    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...
    Clement, Nov 25, 2008
    #1
    1. Advertising

  2. In article
    <>,
    Clement <> wrote:

    [...]
    > 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>

    --
    John B. Matthews
    trashgod at gmail dot com
    http://home.roadrunner.com/~jbmatthews/
    John B. Matthews, Nov 25, 2008
    #2
    1. Advertising

  3. On Tue, 25 Nov 2008 04:15:29 -0800, Clement wrote:

    > 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.


    --
    martin@ | Martin Gregorie
    gregorie. | Essex, UK
    org |
    Martin Gregorie, Nov 25, 2008
    #3
  4. Clement

    Roedy Green Guest

    On Tue, 25 Nov 2008 04:15:29 -0800 (PST), Clement
    <> wrote, quoted or indirectly quoted someone who
    said :

    > 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)
    Roedy Green, Nov 26, 2008
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sojwal Chitnis
    Replies:
    1
    Views:
    2,761
    Jinsong Liu
    Jun 9, 2005
  2. Chris Stiles
    Replies:
    0
    Views:
    447
    Chris Stiles
    Nov 2, 2005
  3. raavi
    Replies:
    1
    Views:
    2,415
    Chris Smith
    Jan 25, 2006
  4. ckyz
    Replies:
    0
    Views:
    4,519
  5. Rickert
    Replies:
    0
    Views:
    642
    Rickert
    Oct 6, 2011
Loading...

Share This Page