麥克斯做個不宅的工程師

Maxi’s idiotic programming.

Deal with java.lang.OutOfMemoryError: Perm-Gen Space

做Portlet 測試時常遇到

PermGen space的全稱是Permanent Generation space,是指記憶體的永久保存區域OutOfMemoryError: PermGen space從表面上看就是記憶體益出,解決方法也一定是加大記憶體。說說為什麼會記憶體益出:這一部分用於存放ClassMeta的資訊,Class在被 Load的時候被放入PermGen space區域,它和和存放InstanceHeap區域不同,GC(Garbage Collection)不會在主程序運行期對PermGen space進行清理,所以如果你的APPLOAD很多CLASS的話,就很可能出現PermGen space錯誤。這種錯誤常見在web伺服器對JSP進行pre compile的時候。

改正方法,在 run.bat 中加入:-Xms256m -Xmx512m -XX:MaxNewSize=256m -XX:MaxPermSize=256m

以上的值都可以自訂,看你的server有強囉

因為項目中引用了很多的 jar 包,而這些 jar 包中的 class 資訊會被 JBoss class loader 載入到 PermGen space 區域,在 JVM 默認的情況下,該部分空間的大小只有 4M,在 jar 包非常多的情況下,顯然是不夠用的,所以通過 -XX:MaxPermSize=256m 指定最大值後即可解決問題。

另外,如果 heap 記憶體不足出現 java.lang.OutOfMemoryError: Java heap space 時,可以通過 -Xmx512m 指定最大 heap 記憶體來解決這樣的問題。

March 20, 2008 , Thursday Posted by maxi326 | Server | , , | No Comments Yet

Develop Portlet (JSR168) with Icefaces

1. Add framework JSF in project properties.

Remember to uncheck library of JSF because we are using Icefaces.

2. In portlet.xml, change <portlet-class> to com.icesoft.faces.webapp.http.portlet.MainPortlet

3. In portlet.xml, add these in

<init-param>
<name>com.icesoft.faces.VIEW</name>
<value>/WEB-INF/jsp/view.iface</value>
</init-param>
<init-param>
<name>com.icesoft.faces.EDIT</name>
<value>/WEB-INF/jsp/edit.iface</value>
</init-param>
<init-param>
<name>com.icesoft.faces.HELP</name>
<value>/WEB-INF/jsp/help.iface</value>
</init-param>

4. In web.xml

The ICEfaces Servlets are registered as follows:

<servlet>
<servlet-name>Persistent Faces Servlet</servlet-name>
<servlet-class>
com.icesoft.faces.webapp.xmlhttp.PersistentFacesServlet
</servlet-class>
<load-on-startup> 1 </load-on-startup>
</servlet>
<servlet>
<servlet-name>Blocking Servlet</servlet-name>
<servlet-class>
com.icesoft.faces.webapp.xmlhttp.BlockingServlet
</servlet-class>
<load-on-startup> 1 </load-on-startup>
</servlet>

The Servlet mappings are established as follows:

<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jspx</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Persistent Faces Servlet</servlet-name>
<url-pattern>*.iface</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Persistent Faces Servlet</servlet-name>
<url-pattern>/xmlhttp/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Blocking Servlet</servlet-name>
<url-pattern>/block/*</url-pattern>
</servlet-mapping>
<listener>
<listener-class>
com.icesoft.faces.util.event.servlet.ContextEventRepeater
</listener-class>
</listener>
<context-param>
<param-name>com.icesoft.faces.concurrentDOMViews</param-name>
<param-value>true</param-value>
</context-param>

5. Sample .jspx for 1.7 beta

<f:view xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ice="http://www.icesoft.com/icefaces/component">
<html>
<head>
<title>
ICEfaces Portlet Chat
</title>
</head>
<body>
<ice:portlet>
<ice:outputStyle href="/xmlhttp/css/xp/xp-portlet.css" />
<f:loadBundle basename=" " var="bundle"/>
<!-- Login/Logout -->
<ice:form>
<ice:outputText value="ICEFACES 1.7"/>
</ice:form>
</ice:portlet>
</body>
</html>
</f:view>

For 1.6

Remove <ice:portlet>

Put <ice:outputStyle> inside <ice:form>

March 20, 2008 , Thursday Posted by maxi326 | Programming | , , | No Comments Yet