Name: rmT116609 Date: 09/17/2004
FULL PRODUCT VERSION :
java version "1.4.2-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-beta-b19)
Java HotSpot(TM) Client VM (build 1.4.2-beta-b19, mixed mode)
java version "1.4.2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)
and J2SE 5.0 RC
FULL OS VERSION :
Windows 2000 with Service Pack 4
A DESCRIPTION OF THE PROBLEM :
Error in DOS console is:
Exception in thread "main" java.lang.OutOfMemoryError
#
# HotSpot Virtual Machine Error, Internal Error
# Please report this error at
# http://java.sun.com/cgi-bin/bugreport.cgi
#
# Java VM: Java HotSpot(TM) Server VM (1.4.2-beta-b19 mixed mode)
#
# Error ID: 455843455054494F4E530E4350500104
#
# Problematic Thread: prio=5 tid=0x00235758 nid=0xd30 runnable
#
Heap at VM Abort:
Heap
def new generation total 13120K, used 0K [0x10010000, 0x10e40000, 0x10e40000)
eden space 11712K, 0% used [0x10010000, 0x10010000, 0x10b80000)
from space 1408K, 0% used [0x10b80000, 0x10b80000, 0x10ce0000)
to space 1408K, 0% used [0x10ce0000, 0x10ce0000, 0x10e40000)
tenured generation total 116544K, used 5641K [0x10e40000, 0x18010000, 0x18010000)
the space 116544K, 4% used [0x10e40000, 0x113c24a0, 0x113c2600, 0x18010000)
compacting perm gen total 131072K, used 131071K [0x18010000, 0x20010000, 0x20010000)
the space 131072K, 99% used [0x18010000, 0x2000fff0, 0x20010000, 0x20010000)
C:\Vabbi_nt4sContent\Traininig1>java -version
java version "1.4.2-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-beta-b19)
Java HotSpot(TM) Client VM (build 1.4.2-beta-b19, mixed mode)
Java version was:
java version "1.5.0-rc"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-rc-b63)
Java HotSpot(TM) Client VM (build 1.5.0-rc-b63, mixed mode, sharing)
Exception in thread "main" java.lang.OutOfMemoryError: PermGen space
*******************************************************************************
In my sample application I am dynamically loading Oracle classes12.zip for Oracle driver using URLClassLoader, to connect to Oracle DB in a for loop and it fails after a certain number of times Here is the code that I am using:
URLClassLoader urlClassLoader = null;
Class drvrClass = null;
urlClassLoader = new URLClassLoader(urlList); //urlList is array of URL's that has my jars
drvrClass = urlClassLoader.loadClass(driverClassName);
try
{
drvr = (Driver) drvrClass.newInstance();
Properties props = new Properties() ;
props.put("user", userName) ;
props.put("password", password) ;
con = drvr.connect(dbURL, props) ;
String sql_sr= "SELECT * from abc";
pstmtQ = con.prepareStatement(sql_sr);
rs=pstmtQ.executeQuery();
while (rs.next()) {
id = rs.getInt(3);
build = rs.getInt(4)
}
}
catch (Exception e)
{
e.printStackTrace();
}
..... I null the objects in the finally clause.
Now this whole code is within a for loop and I get teh above error after a certain iterations. I also print the memory parameters and just before the exception I got
MEMORY_MONITOR_CURRENT_MEMORY_USED = 5.5257720947265625 MB
MEMORY_MONITOR_FREE_MEMORY_ON_HEAP = 121.09922790527344 MB
MEMORY_MONITOR_TOTAL_MEMORY_ON_HEAP = 126.625 MB
-- Vikas
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the sample code in a for loop and it will fail.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.File;
import java.io.FilenameFilter;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.Statement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Properties;
public class MemTest {
private static Runtime rt = java.lang.Runtime.getRuntime();// runtime pointer
public static void main (String args[])
{
long t = System.currentTimeMillis();
MemTest test = new MemTest();
for (int i=0; i< 200; i++)
{
System.out.println("Iteration # " + i + " " + test.getResult());
try
{
Thread.sleep(100);
}
catch (Exception e)
{
e.printStackTrace();
}
long currentFreeMem = rt.freeMemory(); // get free memory on heap
long currentTotalMem = rt.totalMemory();// and total heap memory
long usedMem = currentTotalMem - currentFreeMem;// heap memory in use
System.out.println("MEMORY_MONITOR_CURRENT_MEMORY_USED = " + usedMem/1048576.0 + " MB");
System.out.println("MEMORY_MONITOR_FREE_MEMORY_ON_HEAP = " + currentFreeMem/1048576.0 + " MB");
System.out.println("MEMORY_MONITOR_TOTAL_MEMORY_ON_HEAP = " + currentTotalMem/1048576.0 + " MB");
}
System.out.println(" Time taken " + (System.currentTimeMillis() - t) + " milliseconds");
}
public String getResult() {
int id = 0;
int build = 0;
PreparedStatement pstmtQ = null;
Connection conn = null;
ResultSet rs = null;
try {
conn = getConnection();
}
catch (Exception e) {
e.printStackTrace();
}
finally
{
try {
pstmtQ.close();
rs.close();
conn.close();
}
catch (Exception ex1)
{
}
}
return "hello";
}
private Connection getConnection() throws Exception
{
Connection con = null;
String driverClassName = "oracle.jdbc.driver.OracleDriver";
String dbURL = "jdbc:oracle:thin:@abcd:1521:xyz";
String userName = "user";
String password = "password";
URLClassLoader urlClassLoader = null;
Class drvrClass = null;
URL[] urlList = buildJavaActionClassPathUrls("C:\\testDir", null) ;
if ((urlList != null) && (urlList.length > 0)) { // if ClassPath specified
urlClassLoader = new URLClassLoader(urlList);
drvrClass = urlClassLoader.loadClass(driverClassName);
}
else
{ // if ClassPath not specified
drvrClass = Class.forName(driverClassName, true, ClassLoader.getSystemClassLoader());
}
Driver drvr = null;
try
{
drvr = (Driver) drvrClass.newInstance();
Properties props = new Properties() ;
props.put("user", userName) ;
props.put("password", password) ;
con = drvr.connect(dbURL, props) ;
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
drvr = null;
urlClassLoader = null;
drvrClass = null;
return con;
}
}
public URL[] buildJavaActionClassPathUrls(String serverRoot, String actionClassPath) {
ArrayList urls = new ArrayList();
try
{
if ((actionClassPath != null) && (actionClassPath.length() > 0))
urls.add(new File(actionClassPath).toURL());
if (serverRoot != null && serverRoot.length() > 0) {
File libdir = new File(serverRoot, "lib") ;
if (libdir.exists() && libdir.isDirectory()) {
File[] jars = libdir.listFiles(new JarZipFileFilter()) ;
for (int i = 0 ; i < jars.length; i++)
urls.add(jars[i].toURL()) ;
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
return (URL[]) urls.toArray(new URL[urls.size()]) ;
}
}
private class JarZipFileFilter implements FilenameFilter {
public JarZipFileFilter() {
}
public boolean accept(File dir, String name) {
boolean rslt = false ;
if (name.toLowerCase().endsWith(".jar") || name.toLowerCase().endsWith(".zip"))
rslt = true ;
return rslt ;
}
}
}
---------- END SOURCE ----------
(Incident Review ID: 310600)
======================================================================