0

I have:

Map<String, ExtractData> extractMap = new HashMap<String, ExtractData>();

Why would the following method not get return data from the method it calls?

private void fetchExtractData(CentralExportSession exportSession) throws RemoteException {
    System.out.println("Fetching Extract Data");
    extractMap = exportSession.getExtractData(consDB);
    System.out.printLn("Extract Data Fetched");
}

This calls into:

public Map<String, ExtractData> getExtractData(DataSourceInfo ds) throws RemoteException {
    Connection conn = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    Map<String, ExtractData> extractMap = new HashMap<String, ExtractData>();

    String qry = "...select statement that returns about 500k rows...;"

    try {
        conn = getConnection();
        ps = conn.PrepareStatment(qry);
        rs = ps.executeQuery();

        while (rs.next()) {
            String dataKey = rs.getString("key");
            ExtractData data = new ExtractData();
            ...code that builds up the 'data' object from the result...
            extractMap.put(dataKey, data);
            System.out.println("Added key : " + dataKey);
        }
    } catch (SQLException e) {
        e.printStackTrace();
        throw new EJBException(e);
    } finally {
        System.out.println("Cleaning up...");
        cleanup(conn, ps, rs);
        System.out.println("Returning Map extractMap..."); 
        return extractMap;
    }
}

The "Fetching Extract Data" prints, as do the "Added Key :", "Cleaning up..." and "Returning Map extractMap..." but not the "Extract Data Fetched" in the calling method. I get no visible exceptions, control just is never passed back to the calling method and my CPU usage goes through the roof until I kill it.

Edit: I've tried moving the "return" statement to both inside the "try" block (after the "while") and after the "finally" block with no difference. The location of the return statement does not affect the (lack of) outcome.

It seems to be a memory issue as artificially limiting the resultset to 200k rows allows it to run, but once I go much past that...

  • Using a debugger and a breakpoint inside your `fetchExtractData` method, you should be able to know what exception is thrown and why. And this exception is caught by another method in the stack, it might not print in the console – HBo Apr 16 '18 at 11:02
  • 2
    you are returning from a finally block: https://stackoverflow.com/a/18205628/3959856 – Jack Flamp Apr 16 '18 at 11:03
  • @JackFlamp agree with that post, but since there is some data recovered, the map should still be populated I believe (with some incomplete data most likely based on where this break. – AxelH Apr 16 '18 at 11:06
  • 1
    One thing that Jack Flamp mentioned is that you are returning from finally. Second thing that I see is that you are probably using EJBs - EJBException thrown in catch block. Are you calling this method from an EJB? If so - but it depends on configuration - most probably, invocation of this methods are transactional, and when exception is thrown state of EJB is rolled back if you are using i.e. Stateful Session Beans. – bpawlowski Apr 16 '18 at 11:08
  • Possible duplicate of [Can we use "return" in finally block](https://stackoverflow.com/questions/18205493/can-we-use-return-in-finally-block) – Number945 Apr 16 '18 at 12:03
  • I would recommend to reduce the size of the ResultSet (using a WHERE clause) and then debug it step by step. – OdinOxin Apr 16 '18 at 11:03
  • @JackFlamp While that is informative, I've tried returning from both inside the try block itself (After the while loop) and completely outside of it (after the finally) with no difference in the results. – Robin Fletcher Apr 18 '18 at 10:42

0 Answers0