Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can do it this way. It also does the parsing with Jackson:</p> <pre><code>public class Test { public static class MoviesResponse{ public static class Movie{ public String id; public String title; public String year; } public int total; public List&lt;Movie&gt; movies = new ArrayList&lt;&gt;(); public static MoviesResponse fetch(int page){ try { String request = "http://api.rottentomatoes.com/api/public/v1.0/lists/movies/in_theaters.json?page_limit=16&amp;page=" + page + "&amp;country=us&amp;apikey=cj5a4purh8fxgcmrtn95gheu"; HttpClient httpClient = new DefaultHttpClient(); HttpGet httpget = new HttpGet(request); HttpResponse response = httpClient.execute(httpget); BufferedReader rd = new BufferedReader (new InputStreamReader(response.getEntity().getContent())); String line = ""; StringBuilder textView = new StringBuilder(); while ((line = rd.readLine()) != null) { textView.append(line); // System.out.println(textView); } String resp = textView.toString(); ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); return mapper.readValue(resp, MoviesResponse.class); } catch (IOException e) { e.printStackTrace(); throw new RuntimeException(e); } } } public static void main(String[] args) throws Exception { int numberOfSimultaneousThreads = 3; ExecutorService service = Executors.newFixedThreadPool(numberOfSimultaneousThreads); MoviesResponse firstPage = MoviesResponse.fetch(1); System.out.println("firstPage.total = " + firstPage.total); int pageCount = 3; //update it with formula based on firstPage.total and pageSize (i.e. firstPage.total / pageSize + 1) List&lt;Callable&lt;MoviesResponse&gt;&gt; jobs = new ArrayList&lt;&gt;(); for(int i = 2;i &lt;= pageCount;i++){ final int page = i; jobs.add(new Callable&lt;MoviesResponse&gt;() { @Override public MoviesResponse call() throws Exception { return MoviesResponse.fetch(page); } }); } List&lt;Future&lt;MoviesResponse&gt;&gt; results = service.invokeAll(jobs, 2, TimeUnit.MINUTES); for (Future&lt;MoviesResponse&gt; result : results) { for (MoviesResponse.Movie movie : result.get().movies) { System.out.println(movie.title + " (" + movie.year + ")"); } } service.shutdown(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload