Application Partitioning

A simple but dramatic example of the benefits of application partitioning is to run two identical queries on a collection. One query runs on the server and returns only the result of the query; the second query runs on the client, requiring the collection to be copied to the client.[84]

It’s pretty obvious that since the only difference between the two queries is the amount of data being copied across the network, the second query that copies much more data is slower. For the example, I use a large array of strings and create a query that returns that subset of strings that includes the query string, e.g., “el” is included in “hello” but not in “hi.”

The query method is straightforward:

public static String[] getQuery(String obj, String[] array)
  {
    Vector v = new Vector( );
    for (int i = 0; i < array.length; i++)
      if (array[i].indexOf(obj) != -1)
        v.addElement(array[i]);
    String[] result = new String[v.size( )];
    for (int i = 0; i < result.length; i++)
      result[i] = (String) v.elementAt(i);
    return result;
  }

To run the query as a server method, I declare one server method in a server object (i.e., in the ServerObject interface):

public String[] getServerQuery(String obj);

This is also straightforward. The client calls getServerQuery( ) on the server proxy object and receives the results. To run the query on the client, I declare a method (again in the ServerObject interface) giving access to the String array containing the strings to be compared:

public String[] getQueryArray( ...

Get Java Performance Tuning now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.