简体   繁体   中英

Weird DAO design cause of PermGen Errors?

I have inherited a VERY weird design that a previous contacting company used to implement DAOs in Java. I believe that it is the reason I get PermGen errors constantly, but would like to see what others think.

Each DAO has one or more private static final fields. These are of type Table. Table is an abstract class. Each Table implementation is implemented in-line. In a static block, these implementations are put into a static hash map.

Is it possible that since OBJ_MAP holds implementations of the Table class, that this could cause the ClassLoader to never be able to be garbage collected?

import java.sql.Types;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MyDAO {
    private static final Table DESCRIPTION = new TableImpl("MYDESC", Types.VARCHAR);
    private static final Table CODE = new TableImpl("MYCODE", Types.VARCHAR);

    private static final Map<Table, String> OBJ_MAP = new HashMap<Table, String>();

    static {

        OBJ_MAP.put(DESCRIPTION, "description");
        OBJ_MAP.put(CODE, "code");
     }

    @SuppressWarnings("unchecked")
    public List<BusinessType> getAllBusinessTypes() {
        return DAOUtil.executeObjectSelect("Select MYDESC, MYCODE, 
              from MYTABLE", BusinessType.class,
            OBJ_MAP, new BusinessType());
    }
}

如果每个具有某些类类型的静态final字段的类都阻止了ClassLoader的垃圾回收,那么在任何程序中我们都不会走得太远,因此除非您可以提供更多信息(例如,“ DAO是从类加载器A加载的” ,但Table的实现来自类加载器B”,但是那是可行的),我将继续使用“不,那不可能是原因。”

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