Friday, February 25, 2011

Outofmemory when call findxxx many times

hi all:
  I'm not sure i'm using requestfactory+JPA the right way even through i followed the example(expense) step by step. the memory at server side increase everytime i query some data from Entity<i use Mysql>, after several times, the server heap overflow. 

server side:
    public static List<Scenario> findScenarioEntriesByProduct2( Long productId, int startIndex, int maxCount )
    {
        //get all Scenarios from startIndex to startIndex+maxCount
        EntityManager em = entityManager();
        List<Scenario> resultList = new ArrayList<Scenario>();
        try
        {
            Query q = em.createQuery( "select o from Scenario o where o.product.id = :productid" );
            q.setParameter( "productid", productId );
            q.setFirstResult( startIndex );
            q.setMaxResults( maxCount );
            @SuppressWarnings( "unchecked" )
            List<Scenario> rl = q.getResultList();


            rl.size();
            resultList.addAll( rl );
            return resultList;
        }
        catch( Exception ex )
        {
            logger.error( "exception occur!", ex );
        }
        finally
        {
            em.close();
        }
        return Collections.emptyList();
    }

As you can see the code is quite simple and i can't figure out where's the problem. Could anyone help? thanks!

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment