Hi,
Danke für die Antwort.
Moien
Exception in thread „Timer“ java.lang.OutOfMemoryError: Java
heap space
at easyCam.stopThread(easyCam.java:156)
at easyCam.destroy(easyCam.java:311)
Es ist immer der gleiche Stacktrace ?
Ja
Weiss jemand an was das liegt und wie kann ich das problem
löse?
Du verbrauchst zuviel Speicher.
private void stopThread() {
noStopRequested = false;
timerThread.interrupt();
}//private void stopThread()
public void destroy() {
if(!server_stat)
{
stopThread();
}
}// public void destroy()
- fehlen da die Zeilennummern und 2. liegt es mit Sicherheit
nicht an den paar harmlosen Zeilen. Poste die Klasse mal ganz,
dann sehen wir weiter.
import java.applet.Applet;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.*;
import java.util.Date;
import javax.imageio.ImageIO;
/***************************************************************************************************
**C Classname:
**C Parameter: none
**C Description: to paint and control live image, to paint achsen, help lines, mouse Position and value of color position
**C Return value: none
**C Autor: H. Azza, TietoEnator
**C*************************************************************************************************/
public class easyCam extends Applet implements MouseMotionListener {
private Image myImage;
private BufferedImage im;
URL url;
boolean urlState = true;
String urlString;
/******/
Font beschriftung = new Font(„Arial“, Font.PLAIN, 10);
Dimension d;
float xMin, xMax, yMin, yMax;
float xStep, yStep;
float appletWidth; // wichtig fuer berechnung calcPosX()
float appletHight; // wichtig fuer berechnung calcPosY()
float zoomFactor;
/******/
private Date date;
private int sleepTime = 300;
private String fileBase;
private String fileExtension;
private int imageWidth;
private int imageHeight;
private String srtImageWidth;
private String strImageHeight;
private String strImageZoom;
private int titleIndex;
private Thread timerThread;
private volatile boolean noStopRequested;
private MediaTracker tracker;
int xpos = 0;
int ypos = 0;
int eraseX_Line = 0;
int eraseY_Line = 0;
int rect1xco, rect1yco, rect1width, rect1height;
double posFactor;
int[] al = new int[2];
boolean farbeValue = false;
double farbeFactor = 0;
long endTime, startTime;
int ColorValue;
boolean imagestart = false; //um das Problem von paint zu vermeiden :
String sActiveStat;
boolean server_stat = false;
/***************************************************************************************************
**F Functionname:
**F Parameter: none
**F Description: Function to unit applet and mask
**F Return value: none
**F Autor: H. Azza, TietoEnator
**F*************************************************************************************************/
public void init() {
sActiveStat = getParameter(„ACTIVESTAT“);
System.out.println(„sActiveStat“ + sActiveStat);
if(!sActiveStat.equals(„0“)) // machine is actived
{
farbeValue = false;
//imageload = false;
tracker = new MediaTracker(this);
fileBase = getParameter(„FILEBASE“);
fileExtension = getParameter(„FILEEXT“);
urlString = new String(getCodeBase() + fileBase + fileExtension);
startThread();
srtImageWidth = getParameter(„IMAGEWIDTH“);
strImageHeight = getParameter(„IMAGEHEIGHT“);
strImageZoom = getParameter(„IMAGEZOOM“);
String strSleepTime = getParameter(„MSDELAY“);
if (srtImageWidth != null)
imageWidth = Integer.parseInt(srtImageWidth);
if (strImageHeight != null)
imageHeight = Integer.parseInt(strImageHeight);
System.out.println("srtImageWidth: " + srtImageWidth);
if (strSleepTime != null)
sleepTime = Integer.parseInt(strSleepTime);
System.out.println("sleepTime: " + sleepTime);
if (strImageZoom.equals(„ZOOM“)) {
titleIndex = 400;
posFactor = (double) 2 / 1.6;
farbeFactor = 1.6;
} else if (imageWidth == 640) {
titleIndex = 230;
posFactor = 2;
farbeFactor = 1;
} else {
System.out.println("full: ");
titleIndex = 460;
posFactor = 1;
farbeFactor = 1;
}
addMouseMotionListener(this);
}
else
{
server_stat = true;
}
}//public void init()
/***************************************************************************************************
**F Functionname:
**F Parameter: none
**F Description: Function to start thread
**F Return value: none
**F Autor: H. Azza, TietoEnator
**F*************************************************************************************************/
private void startThread() {
noStopRequested = true;
Runnable r = new Runnable() {
public void run() {
runWork();
}
};
timerThread = new Thread(r, „Timer“);
timerThread.start();
}//private void startThread()
/***************************************************************************************************
**F Functionname:
**F Parameter: none
**F Description: Function to stop thread
**F Return value: none
**F Autor: H. Azza, TietoEnator
**F*************************************************************************************************/
private void stopThread() {
noStopRequested = false;
timerThread.interrupt();
}//private void stopThread()
/***************************************************************************************************
**F Functionname:
**F Parameter: none
**F Description: Function to read live image
**F Return value: none
**F Autor: H. Azza, TietoEnator
**F*************************************************************************************************/
private void runWork() {
boolean imageload = false;
try {
while (noStopRequested) {
if (imageload == true) {
tracker.removeImage(myImage);
//myImage.flush();
//myImage = null;
}
try {
//System.out.println("1: ");
date = new Date();
startTime = date.getTime();
myImage = ImageIO.read(new URL(urlString)); // read live image
//System.out.println("2: ");
imagestart = true;
endTime = new Date().getTime() - startTime; // lade zeit
im = (BufferedImage) myImage;
//System.out.println("3: ");
if (farbeValue)
//try {
ColorValue = im.getRGB((int) (xpos / farbeFactor),(int) (ypos / farbeFactor));
/* } catch (ArrayIndexOutOfBoundsException e) {
//System.out.println(„Farbe Exception“ + e.toString());
farbeValue = false;
}
} */
//System.out.println("4: ");
tracker.addImage(myImage, 0);
tracker.waitForAll();
imageload = true;
//System.out.println("5: ");
repaint();
Thread.yield(); // give control to another thread
//System.out.println("6: ");
}
catch(MalformedURLException e2){
//System.out.println(e2.toString());
System.out.println(„url error1“);
}
catch(IOException e1){
//System.out.println(e1.toString());
System.out.println(„url error22“);
}
catch(NullPointerException ae)
{
System.out.println(„read error3“);
//ae.printStackTrace();
}
catch (ArrayIndexOutOfBoundsException e) {
//System.out.println(„Farbe Exception“ + e.toString());
farbeValue = false;
}
//System.out.println("7: ");
Thread.sleep(sleepTime);
//System.out.println("8: ");
}
} catch (InterruptedException x) {
//System.out.println(„thread Exception“ + x.toString());
Thread.currentThread().interrupt();
}
}// private void runWork()
/***************************************************************************************************
**F Functionname:
**F Parameter: Graphics
**F Description: Function to update live image
**F Return value: none
**F Autor: H. Azza, TietoEnator
**F*************************************************************************************************/
public void paint(Graphics g) {
update(g);
}// public void paint(Graphics g)
/***************************************************************************************************
**F Functionname:
**F Parameter: Graphics
**F Description: Function to paint live image
**F Return value: none
**F Autor: H. Azza, TietoEnator
**F*************************************************************************************************/
public void update(Graphics g) {
if (myImage != null)
{
//urlState = true;
Font font;
eraseX_Y_Line(g);
raster(g, imageWidth, imageHeight); // zeichnen eines rasters
koordinatenSystem(g, imageWidth, imageHeight); //zeichnen der achsen
g.clearRect(122, imageHeight + 86, 50, 40); //clear position x and y
g.drawString(
„Position-X: " + (int) (xpos * posFactor) + " px“,
64,
imageHeight + 96);
g.drawString(
„Position-Y: " + (int) (ypos * posFactor) + " px“,
64,
imageHeight + 122);
g.clearRect((int) (imageWidth / 2), imageHeight + 85, 95, 40); //clear color and time
if (!farbeValue)
g.drawString("Color: ", (int) (imageWidth / 2), imageHeight + 96); //farbe-info
else
g.drawString(
"Color: " + (ColorValue & 0x000000ff) + „“,
(int) (imageWidth / 2),
imageHeight + 96); //farbe-info
g.drawString(
„Time: " + endTime + " ms“,
(int) (imageWidth / 2),
imageHeight + 122); //Ladezeit info.
drawX_Y_Line(g); // Zeichnen von Hilf-line X und Y
g.drawImage(myImage, 64, 74, imageWidth, imageHeight, this); //Bild
//g.drawImage(imageLogo,imageWidth + 20,imageHeight + 76, 30, 30, this); //Bild
}
if (myImage == null && imagestart)//Error
{
g.setColor(Color.red);
g.drawString(„Error:“, 100,100);
g.drawString(„Can’t get image from URL!“, 120,120);
}
else
if(server_stat)
{
g.setColor(Color.red);
g.drawString(„Warning:“, 100,100);
g.drawString(„Image not accessible!“, 120,120);
g.drawString(„Machine is activ!“, 120,140);
}
}//public void update(Graphics g)
/***************************************************************************************************
**F Functionname:
**F Parameter: none
**F Description: Function to stop thread
**F Return value: none
**F Autor: H. Azza, TietoEnator
**F*************************************************************************************************/
public void destroy() {
if(!server_stat)
{
stopThread();
}
//myImage.flush();
//myImage = null;
}// public void destroy()
/***************************************************************************************************
**F Functionname:
**F Parameter: Graphics, imageWidth and imageHeight
**F Description: Function to paint kordinatensystem (achsen)
**F Return value: none
**F Autor: H. Azza, TietoEnator
**F*************************************************************************************************/
public void koordinatenSystem(
Graphics g,
int imageWidth,
int imageHeight) {
g.setColor(Color.black);
g.drawLine(60, 70, imageWidth + 64, 70);
g.drawLine(60, 70, 60, imageHeight + 74);
} //koordinatenSystem
// *****************************************************************
// Die Methode raster zeichnet ein raster in das koordinatensystem.
//
// *****************************************************************
/***************************************************************************************************
**F Functionname:
**F Parameter: Graphics, imageWidth and imageHeight
**F Description: Function to paint raster
**F Return value: none
**F Autor: H. Azza, TietoEnator
**F*************************************************************************************************/
public void raster(Graphics g, int imageWidth, int imageHeight) {
int i = 64;
int count = 0;
int schrift;
int mod, weit, distance;
boolean line_50 = false;
g.setColor(Color.black);
g.drawString(String.valueOf(0), 40, 70); //0 als zahl einfügen
g.drawString(String.valueOf(1280), imageWidth + 70, 70);//1024 als zahl einfügen
g.drawString(String.valueOf(1024), 25, imageHeight + 79);//768 als zahl einfügen
g.drawString(„X / Pixel“, imageWidth + 70, 40); // X / Pixel als String einfügen
g.drawString(„Y“, 15, 80); // Y als String einfügen
g.drawLine(10, 83, 35, 83);
g.drawString(„Pixel“, 10, 95); // Pixel als String einfügen
if (imageWidth == 640) // half Bild
{
schrift = 100;
weit = 100;
distance = 10;
} else if (imageWidth == 1024) // gezoomtes Bild: zoom faktor = 1.6
{
schrift = 100;
weit = 100;
distance = 16; //10*1.6
line_50 = false;
} else // full Bild
{
schrift = 50;
weit = 50;
distance = 10;
line_50 = true;
}
while (i
**F Parameter: MouseEvent
**F Description: Function to control mouse event
**F Return value: none
**F Autor: H. Azza, TietoEnator
**F*************************************************************************************************/
public void mouseMoved(MouseEvent me) {
xpos = me.getX();
ypos = me.getY();
if (xpos = imageWidth + 64
|| ypos >= imageHeight + 74) {
eraseX_Line = 1;
xpos = 0;
ypos = 0;
farbeValue = false;
} else {
eraseX_Line = 1;
xpos = xpos - 64;
ypos = ypos - 74;
farbeValue = true;
}
} // public void mouseMoved(MouseEvent me)
public void mouseDragged(MouseEvent me) {
}
/***************************************************************************************************
**F Functionname:
**F Parameter: Graphics
**F Description: Function to paint 2 help lines
**F Return value: none
**F Autor: H. Azza, TietoEnator
**F*************************************************************************************************/
public void drawX_Y_Line(Graphics g) {
if (xpos != 0 && ypos != 0) {
g.setColor(Color.red);
g.drawLine(xpos + 64, 0, xpos + 64, 70);
// Zeichnen von Hilfs-line X
g.drawLine(0, ypos + 74, 60, ypos + 74);
// Zeichnen von Hilfs-line Y
al[0] = xpos; //Letzte x-position von Hilfs-line X speichern
al[1] = ypos; //Letzte y-position von Hilfs-line Y speichern
}
} // public void drawX_Y_Line(Graphics g)
/***************************************************************************************************
**F Functionname:
**F Parameter: Graphics
**F Description: Function to delete 2 help lines
**F Return value: none
**F Autor: H. Azza, TietoEnator
**F*************************************************************************************************/
public void eraseX_Y_Line(Graphics g) {
if (eraseX_Line == 1) {
g.clearRect(al[0] + 63, 0, 2, 70); // Löschen von Hilfs-line X
g.clearRect(0, al[1] + 73, 60, 2); // Löschen von Hilfs-line Y
eraseX_Line = 0;
}
}// public void eraseX_Y_Line(Graphics g)
}//public class easyCam extends Applet implements MouseMotionListener
cu
Gruss.
Hicham