Mahlzeit und Guten Tag Community,
ich habe mir eine Klasse geschrieben, welche als eigentständiger Thread fungieren soll. Hierbei tritt nun des öfteren ein PermGenSpace-Fehler auf. Könntet ihr mir dort mal weiterhelfen / erklären woran es liegen könnte?
Hier der Quellcode:
[JAVA=344]
/**
* Diese Funktion schreibt die Datenquelle in die Datenbank
*/
public String datenQuellePersistieren() throws NullPointerException, PreexistingEntityException, ClassNotFoundException, SQLException, Exception {
BufferedReader br = null;
ArrayList<String> col = new ArrayList<String>();
if (this._ueberschreiben) {
try {
MsSql.getInstance().dropTable(this._tableName);
} catch (ClassNotFoundException ex) {
Logger.getLogger(DatenquelleRueiXml.class.getName()).log(Level.ERROR, null, ex);
} catch (SQLException ex) {
Logger.getLogger(DatenquelleRueiXml.class.getName()).log(Level.ERROR, null, ex);
}
this.createTableForThis();
}
/* Pro Pfad einmal auslesen */
Set<String> cnfs = this.getColumnNamesFromSQL();
ArrayList<String> alcnfs = new ArrayList<String>();
for (String s : cnfs) {
alcnfs.add(s);
}
try {
br = Hilfe.getBufferedReaderFromHttpsUrl(this.getId());
String line;
line = br.readLine(); // Line enthaelt nur den XML Versions Tag (<?xml version="1.0" encoding="UTF-8"?>)
line = br.readLine(); // Line enthaelt nur den Tag fuer den Anfang des Reports (<report>)
/*
* Hier wird nun die ID ermittelt damit der Tabellen Name herausgefunden wird
*/
line = br.readLine();
br.readLine(); // Line enthaelt nur den Namen des Reports (<name>****</name>)
String toAdd;
while ((line = br.readLine()) != null) {
if (line.equals("<row>")) {
while (!(line = br.readLine()).equals("</row>")) {
toAdd=line.substring(line.indexOf("<name>") + 6, line.indexOf("</name>"));
if(toAdd.equals("n/a")){
toAdd="0";
}
col.add(toAdd);
}
try {
int anzahlDerNullwerte=0;
for(String s:col){
if(s.equals("0")){
anzahlDerNullwerte++;
}
}
if(anzahlDerNullwerte<(col.size())){
MsSql.getInstance().insertInto(this._tableName, col, alcnfs);
}
} catch (SQLServerException e) {
Logger.getLogger(DatenquelleRueiXml.class.getName()).log(Level.ERROR, null, e);
}
col.clear();
}
}
} catch (Exception ex) {
if (ex instanceof SQLServerException) {
throw (SQLServerException) ex;
}
Logger.getLogger(DatenquelleRueiXml.class.getName()).log(Level.ERROR, null, ex);
} finally {
try {
br.close();
} catch (IOException ex) {
Logger.getLogger(DatenquelleRueiXml.class.getName()).log(Level.ERROR, null, ex);
}
}
return "";
}
public String updateData() throws PreexistingEntityException, Exception {
String datenQuellePersistieren = this.datenQuellePersistieren();
this._lastUpdate = Calendar.getInstance().getTime();
JpaController jpc = JpaController.getInstance();
jpc.edit(this);
return "";
}[/code]
[JAVA=124]
/**
* Dieser Befehl fuegt nur eine Zeile hinu
* @param tableName
* @param values
* @return
*/
public void insertInto(String tableName, ArrayList<String> values, ArrayList<String> columns) throws NullPointerException, SQLException, ClassNotFoundException {
StringBuilder sbInsert = new StringBuilder();
StringBuilder sbSelect = new StringBuilder();
StringBuilder sbUpdate = new StringBuilder();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
int spaltennnummer = 0;
int pkcid = 0;
String firstWert = "";
try {
pkcid = MsSqlBefehlsvorlagen.findPrimaryKeyColumnId(tableName);
} catch (NullPointerException npe) {
throw npe;
}
ResultSet rs = this.executeQuery("SELECT DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME LIKE '" + tableName + "' ORDER BY ORDINAL_POSITION;");
boolean t = true;
boolean firstRun = true;
LinkedList<String> lls = new LinkedList<String>();
while (t) {
rs.next();
try {
lls.add(rs.getString(1));
} catch (SQLServerException sse) {
break;
}
}
sbInsert.append("INSERT INTO [dbo].[").append(tableName).append("] VALUES( ");
sbUpdate.append("UPDATE [dbo].[").append(tableName).append("] SET ");
for (String a : values) {
String b = a;
if (lls.get(spaltennnummer).equals("float")) {
a = a.replace(".", "");
a = a.replace(",", ".");
b = Double.valueOf(a).toString();
} else if (lls.get(spaltennnummer).equals("datetime")) {
String[] split = a.split(":");
Calendar calendarInstance = Calendar.getInstance();
calendarInstance.setTime(new Date());
calendarInstance.set(Calendar.HOUR_OF_DAY, Integer.valueOf(split[0]));
calendarInstance.set(Calendar.MINUTE, Integer.valueOf(split[1]));
calendarInstance.set(Calendar.SECOND, 0);
calendarInstance.set(Calendar.MILLISECOND, 0);
a = this.formatDateToString(calendarInstance.getTime());
b = this.formatDateToString(calendarInstance.getTime());
firstWert = a;
} else if (lls.get(spaltennnummer).equals("varchar")) {
a = a.replace(".", "");
a = a.replace(",", ".");
b = a;
if (firstRun) {
firstWert = a;
firstRun = false;
}
}
sbInsert.append("'");
sbUpdate.append("[").append(columns.get(spaltennnummer)).append("] = '");
sbInsert.append(b).append("',");
sbUpdate.append(b).append("',");
spaltennnummer++;
}
sbInsert.delete(sbInsert.length() - 1, sbInsert.length());
sbInsert.append(")");
sbUpdate.delete(sbUpdate.length() - 1, sbUpdate.length());
sbUpdate.append(" WHERE [").append(columns.get(pkcid - 1)).append("] = '").append(firstWert).append("'");
sbSelect.append("SELECT [").append(columns.get(pkcid - 1)).append("] FROM [dbo].[").append(tableName).append("] ").append(" WHERE [").append(columns.get(pkcid - 1)).append("] = '").append(firstWert).append("'");
String sql = "IF NOT EXISTS (" + sbSelect.toString() + ") " + sbInsert.toString() + " ELSE " + sbUpdate.toString();
this.executeSQL(sql);
}
[/code]
Ich hoffe ihr könnt mir helfen... Danke schonmal
ich habe mir eine Klasse geschrieben, welche als eigentständiger Thread fungieren soll. Hierbei tritt nun des öfteren ein PermGenSpace-Fehler auf. Könntet ihr mir dort mal weiterhelfen / erklären woran es liegen könnte?
Hier der Quellcode:
Java:
package esd.helfer;
import java.sql.SQLException;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import esd.entities.DatenquelleXml;
import esd.jpaController.JpaController;
import esd.jpaController.exceptions.PreexistingEntityException;
/**
*
*/
public class DatenquellenUpdater extends Thread {
private static DatenquellenUpdater instance;
public static int durchlaeufe;
private DatenquellenUpdater() {
durchlaeufe = 0;
this.setPriority(Thread.MAX_PRIORITY - 1);
this.setName("eStatisticsDashboardDatenquellenUpdaterThread Prio:" + this.getPriority());
}
public static synchronized DatenquellenUpdater getInstance() {
if (instance == null) {
instance = new DatenquellenUpdater();
Calendar.getInstance().getTime() + " - " + " - NEW INSTANCE CREATED");
String text = (Calendar.getInstance().getTime().toString() + " - DatenquellenUpdater started, now update process is running until undeploy Application eStatisticDashboard.");
Logger.getLogger(DatenquellenUpdater.class.getName()).log(Level.INFO, text, null);
}
return instance;
}
@Override
public synchronized void run() {
JpaController jpc;
List<DatenquelleXml> findObjectEntities;
Date start, end;
long diff;
String text = "";
while (true) {
try {
jpc = JpaController.getInstance();
start = Calendar.getInstance().getTime();
findObjectEntities = jpc.findObjectEntities(DatenquelleXml.class);
for (DatenquelleRueiXml d : findObjectEntities) {
d.updateData();
Calendar.getInstance().getTime() + " - " + " - " + d.getId());
}
durchlaeufe++;
end = Calendar.getInstance().getTime();
if ((end.getTime() - start.getTime()) > 0
&& (end.getTime() - start.getTime()) < (5 * 60 * 1000)) {
diff = (5*60*1000)-(end.getTime() - start.getTime());
} else {
diff = 0;
}
if (durchlaeufe == 6) {
text = (Calendar.getInstance().getTime().toString() + " - DatenquellenUpdater pass all updates " + durchlaeufe + " time eStatisticDashboard.");
Logger.getLogger(DatenquellenUpdater.class.getName()).log(Level.INFO, text, null);
durchlaeufe = 0;
}
if (diff > 0) {
DatenquellenUpdater.sleep(diff);
}
start = null;
end = null;
diff = 0;
text = null;
findObjectEntities = null;
jpc = null;
} catch (NullPointerException ex) {
Logger.getLogger(DatenquellenUpdater.class.getName()).log(Level.ERROR, ex.getMessage(), ex);
} catch (PreexistingEntityException ex) {
Logger.getLogger(DatenquellenUpdater.class.getName()).log(Level.ERROR, ex.getMessage(), ex);
} catch (ClassNotFoundException ex) {
Logger.getLogger(DatenquellenUpdater.class.getName()).log(Level.ERROR, ex.getMessage(), ex);
} catch (SQLException ex) {
Logger.getLogger(DatenquellenUpdater.class.getName()).log(Level.ERROR, ex.getMessage(), ex);
} catch (IllegalThreadStateException ex) {
Logger.getLogger(DatenquellenUpdater.class.getName()).log(Level.ERROR, ex.getMessage(), ex);
} catch (Exception ex) {
Logger.getLogger(DatenquellenUpdater.class.getName()).log(Level.ERROR, ex.getMessage(), ex);
}
}
}
}
[JAVA=344]
/**
* Diese Funktion schreibt die Datenquelle in die Datenbank
*/
public String datenQuellePersistieren() throws NullPointerException, PreexistingEntityException, ClassNotFoundException, SQLException, Exception {
BufferedReader br = null;
ArrayList<String> col = new ArrayList<String>();
if (this._ueberschreiben) {
try {
MsSql.getInstance().dropTable(this._tableName);
} catch (ClassNotFoundException ex) {
Logger.getLogger(DatenquelleRueiXml.class.getName()).log(Level.ERROR, null, ex);
} catch (SQLException ex) {
Logger.getLogger(DatenquelleRueiXml.class.getName()).log(Level.ERROR, null, ex);
}
this.createTableForThis();
}
/* Pro Pfad einmal auslesen */
Set<String> cnfs = this.getColumnNamesFromSQL();
ArrayList<String> alcnfs = new ArrayList<String>();
for (String s : cnfs) {
alcnfs.add(s);
}
try {
br = Hilfe.getBufferedReaderFromHttpsUrl(this.getId());
String line;
line = br.readLine(); // Line enthaelt nur den XML Versions Tag (<?xml version="1.0" encoding="UTF-8"?>)
line = br.readLine(); // Line enthaelt nur den Tag fuer den Anfang des Reports (<report>)
/*
* Hier wird nun die ID ermittelt damit der Tabellen Name herausgefunden wird
*/
line = br.readLine();
br.readLine(); // Line enthaelt nur den Namen des Reports (<name>****</name>)
String toAdd;
while ((line = br.readLine()) != null) {
if (line.equals("<row>")) {
while (!(line = br.readLine()).equals("</row>")) {
toAdd=line.substring(line.indexOf("<name>") + 6, line.indexOf("</name>"));
if(toAdd.equals("n/a")){
toAdd="0";
}
col.add(toAdd);
}
try {
int anzahlDerNullwerte=0;
for(String s:col){
if(s.equals("0")){
anzahlDerNullwerte++;
}
}
if(anzahlDerNullwerte<(col.size())){
MsSql.getInstance().insertInto(this._tableName, col, alcnfs);
}
} catch (SQLServerException e) {
Logger.getLogger(DatenquelleRueiXml.class.getName()).log(Level.ERROR, null, e);
}
col.clear();
}
}
} catch (Exception ex) {
if (ex instanceof SQLServerException) {
throw (SQLServerException) ex;
}
Logger.getLogger(DatenquelleRueiXml.class.getName()).log(Level.ERROR, null, ex);
} finally {
try {
br.close();
} catch (IOException ex) {
Logger.getLogger(DatenquelleRueiXml.class.getName()).log(Level.ERROR, null, ex);
}
}
return "";
}
public String updateData() throws PreexistingEntityException, Exception {
String datenQuellePersistieren = this.datenQuellePersistieren();
this._lastUpdate = Calendar.getInstance().getTime();
JpaController jpc = JpaController.getInstance();
jpc.edit(this);
return "";
}[/code]
[JAVA=124]
/**
* Dieser Befehl fuegt nur eine Zeile hinu
* @param tableName
* @param values
* @return
*/
public void insertInto(String tableName, ArrayList<String> values, ArrayList<String> columns) throws NullPointerException, SQLException, ClassNotFoundException {
StringBuilder sbInsert = new StringBuilder();
StringBuilder sbSelect = new StringBuilder();
StringBuilder sbUpdate = new StringBuilder();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
int spaltennnummer = 0;
int pkcid = 0;
String firstWert = "";
try {
pkcid = MsSqlBefehlsvorlagen.findPrimaryKeyColumnId(tableName);
} catch (NullPointerException npe) {
throw npe;
}
ResultSet rs = this.executeQuery("SELECT DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME LIKE '" + tableName + "' ORDER BY ORDINAL_POSITION;");
boolean t = true;
boolean firstRun = true;
LinkedList<String> lls = new LinkedList<String>();
while (t) {
rs.next();
try {
lls.add(rs.getString(1));
} catch (SQLServerException sse) {
break;
}
}
sbInsert.append("INSERT INTO [dbo].[").append(tableName).append("] VALUES( ");
sbUpdate.append("UPDATE [dbo].[").append(tableName).append("] SET ");
for (String a : values) {
String b = a;
if (lls.get(spaltennnummer).equals("float")) {
a = a.replace(".", "");
a = a.replace(",", ".");
b = Double.valueOf(a).toString();
} else if (lls.get(spaltennnummer).equals("datetime")) {
String[] split = a.split(":");
Calendar calendarInstance = Calendar.getInstance();
calendarInstance.setTime(new Date());
calendarInstance.set(Calendar.HOUR_OF_DAY, Integer.valueOf(split[0]));
calendarInstance.set(Calendar.MINUTE, Integer.valueOf(split[1]));
calendarInstance.set(Calendar.SECOND, 0);
calendarInstance.set(Calendar.MILLISECOND, 0);
a = this.formatDateToString(calendarInstance.getTime());
b = this.formatDateToString(calendarInstance.getTime());
firstWert = a;
} else if (lls.get(spaltennnummer).equals("varchar")) {
a = a.replace(".", "");
a = a.replace(",", ".");
b = a;
if (firstRun) {
firstWert = a;
firstRun = false;
}
}
sbInsert.append("'");
sbUpdate.append("[").append(columns.get(spaltennnummer)).append("] = '");
sbInsert.append(b).append("',");
sbUpdate.append(b).append("',");
spaltennnummer++;
}
sbInsert.delete(sbInsert.length() - 1, sbInsert.length());
sbInsert.append(")");
sbUpdate.delete(sbUpdate.length() - 1, sbUpdate.length());
sbUpdate.append(" WHERE [").append(columns.get(pkcid - 1)).append("] = '").append(firstWert).append("'");
sbSelect.append("SELECT [").append(columns.get(pkcid - 1)).append("] FROM [dbo].[").append(tableName).append("] ").append(" WHERE [").append(columns.get(pkcid - 1)).append("] = '").append(firstWert).append("'");
String sql = "IF NOT EXISTS (" + sbSelect.toString() + ") " + sbInsert.toString() + " ELSE " + sbUpdate.toString();
this.executeSQL(sql);
}
[/code]
Ich hoffe ihr könnt mir helfen... Danke schonmal