简体   繁体   中英

out of memory exception in RMI

Dear all, I am using java rmi for my program, from client side i am calling my interface method by passing single argument. Using this argument interface runs a query and returns 40,000 rows(each row containing 10 row)as a result.All these are stored in vector inside vector structure [[0,1,2,3,4,5,6,7,8,9],[],[],[],[],[]...]. This things happen when i am clicking one button. First time its works but again i am trying to do the same (ie clicking button ) It shows java.lang.out of memory exception at client side . pls help me.I am using Postgresql db.

Client side:
    Vector data = new Vector();
    data = Inter.getEndProductDetailsForCopyChain(endProductId);

Server side:
    public Vector getEndProductDetailsForCopyChain(int endProductId1)
    {
        Connection OPConnect  = StreamLineConnection.GetStreamline_Connection();
        Vector data=new Vector();       
        try{        
            System.out.println("Before query data vector size>>>>>>>>"+data.size());//mohan
            String sqlQry = "select distinct style_no,version_no,matNo,type,specs,color,size,ref_no,uom1 from garment where id=" +endProductId1;
            System.out.println("sqlQry"+ sqlQry);
            Statement st=OPConnect.createStatement();
            ResultSet rs = st.executeQuery(sqlQry);
            while(rs.next()){
                Vector row = new Vector();
                row.add(rs.getString("style_no"));
                row.add(rs.getString("version_no"));
                row.add(rs.getString("matNo"));
                row.add(rs.getString("type"));
                row.add(rs.getString("specs"));
                row.add(rs.getString("color"));
                row.add(rs.getString("size"));
                row.add(rs.getString("ref_no"));
                row.add(rs.getString("uom1"));
                row.add(new Boolean(false));
                data.add(row);
                }
            System.out.println("After query data vector size>>>>>>>>"+data.size());
        }catch(Exception e)
        {    e.printStackTrace();
             closeConnection(OPConnect);
        }
            return data;
       }

I cleared all the vectors and hashmap after finishing my process but still throwing Out of memory exception at client side this happens when data(query result vector) dispatched to client side.

A direct response to your question: if you can change the client JVM command line args, then start with more memory allocated. For example, use -Xmx256M to use max memory of 256 Meg

A more useful response to your question: The way you phrased your question suggests you know the real problem: a program architecture that tries to obtain so much data on a single click. Do you really need to have so much data on the client side? Can you do some processing with it on the server side and send much less? Can you add paging? or lazy loading?

Consider Google's search model as a possible solution...a Google search for "hello" has about 310,000,000 matches, yet Google only sends me 10 results at a time. Then I click "Next" to get more... this is paging. Users cannot typically make much sense of 40,000 rows of data at once. Would this work for you?

If this is for export, fetch 100 or so rows at a time, export them, then fetch the next rows... you really don't want to be transferring so much data via RMI in one call.

Try to re-use data , do not create a new vector on every request. data.clear(); // fill it then data.clear(); // fill it then .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM