Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
    Bookmark Topic Watch Topic
  • New Topic

related to RMI / socket programming

 
yamini nadella
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Report post to moderator
Write pseudo-code for a Java class which implements a single public method::

public int getCalculatedResult(int arg);

This class communicates over a socket to a server process (using message format and protocol of your design). The server process calculates and sends back the integer result which will be returned by the getCalculatedResult call. The server process accepts, queues, and calculates results in an asynchronous, multithreaded way and sends results back over the socket as soon as the results are ready (i.e. results may come back in a different order than they were sent).

The getCalculatedResult method declaration cannot be changed and must behave, to the caller, no differently than if the calculation were happening locally, directly inside the method.

Expect that many threads will be calling the getCalculatedResult method simultanously and each thread expects its result as soon as it is returned by the server.

You may create additional threads and any data structures needed inside the class.

A few notes:

Because the server calculates and returns results asynchronously, and getCalculatedResult() is a synchronous method, the implementation not only must return the right response based on the request, but also must take throughput into consideration.
Using a blocking read on the socket will not be sufficient as results potentially come back out of order.
Synchronizing the getCalculatedResult method is not a reasonable solution as this will cause each thread that calls the method to operate sequentially rather than in parallel, thereby slowing down the throughput of the system.
There is no need to write the server code, assume this is written.
Assume there is a single instance of the class that implements getCalculatedResult() that all calling threads will use.
 
Joe Ess
Bartender
Posts: 9340
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please don't crosspost the same question to multiple forums.
 
Jeff Bosch
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • Report post to moderator
What does this post have to do with SCJD?
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Report post to moderator
I have closed this topic since it is a crosspost and not related to the purpose of this forum (questions relating to the Sun Certified Java Developer assignment and exam).

Regards, Andrew
 
    Bookmark Topic Watch Topic
  • New Topic