title: For Google App Engine (java), how do I set and use chunk size in FetchOptions?
body: <p>Im running a query and it is currently returning 1400 results and because of this I am getting the following warning in the log file:</p>
  
  <blockquote>
    <p>com.google.appengine.api.datastore.QueryResultsSourceImpl
    logChunkSizeWarning: This query does not have a chunk size set in
    FetchOptions and has returned over 1000 results.  If result sets of
    this size are common for this query, consider setting a chunk size to
    improve performance.</p>
  </blockquote>
  
  <p>I can't find any examples anywhere as to how to actually implement this, there is a question on here about python, but as Im using java and dont understand python, I am struggling to translate it.</p>
  
  <p>Also this query (below) is taking 17226cpu_ms to execute, which feels like way too long, I cant even imagine what would happen if I had say 5000 contacts and needed to search through them on the client side (like you do with googlemail contacts!)</p>
  
  <p>The code I have is:</p>
  
  <pre><code>    int index=0;
      int numcontacts=0;
      String[][] DetailList;
  
      PersistenceManager pm = PMF.get().getPersistenceManager();
  
  
      try {
          Query query = pm.newQuery(Contact.class, "AdminID == AID");
          query.declareParameters("Long AID");
          query.setOrdering("Name asc");
          List&lt;Contact&gt; Contacts = (List&lt;Contact&gt;) query.execute(AdminID);
          numcontacts=Contacts.size();
          DetailList=new String[numcontacts][5];
  
          for (Contact contact : Contacts) 
          {
              DetailList[index][0]=contact.getID().toString();
              DetailList[index][1]=Encode.EncodeString(contact.getName());
              index++;
          }
      } finally {
          pm.close();
      }
      return (DetailList);
  </code></pre>
  
  <p>I found the following two entries on here:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/6914069/google-app-engine-chunksize-prefetchsize-where-can-i-read-details-on-it">google app engine chunkSize &amp; prefetchSize - where can I read details on it?</a></li>
  <li><a href="https://stackoverflow.com/questions/1995302/gae-j-low-level-api-fetchoptions-usage">GAE/J Low-level API: FetchOptions usage</a></li>
  </ul>
  
  <p>but neither actually goes into any details about how to implement or use these options.
  Im guessing its a server side process, and Im guessing that you are meant to setup some kind of loop to grab the chunks one chunk at a time, but how do I actually do that?</p>
  
  <ul>
  <li>Do I call the query inside a loop?</li>
  <li>How do I know how many times to loop?</li>
  <li>Do I just check for the first chunk that comes back with less than the chunk size number of entries?</li>
  </ul>
  
  <p>How am I meant to go about finding out stuff like this without an actual example to follow? 
  It seems to me that other people on here seem to "just know" how to do it..!</p>
  
  <p>Sorry If I am not asking the questions in the right way or I'm just being a dim newbie about this, but I dont know where else to turn to figure this out!</p>