EDIT: I tried changing -Xms and -Xmx on the eclipse.ini already but it is still the same. I have a Java GUI program that runs a heavy computation in the background upon an event trigger. If the user input in the program is fairly not that big (less than 200, I think), everything runs smoothly - no lags, and the heatmaps (which are my output) are given and displayed by the program. But if it is indeed a large data, it starts to lag and sometimes, halfway through the process, the program freezes (e.g. somewhere 300~ over 724 data). Take note that if for example, I say 724 data, it means that I am creating 724 heatmaps.
My main Thread from the GUI triggered upon by a button click is as follows...
class ComponentVisualization implements Runnable{
JScrollPane scrollPane;
JPanel panelScroll;
JPanel componentComboBoxPanel;
@Override
public void run(){
scrollPane = new JScrollPane();
panelScroll = new JPanel();
panelScroll.setBorder(new EmptyBorder(10, 10, 10, 10));
panelScroll.setLayout(new BoxLayout(panelScroll, BoxLayout.Y_AXIS));
componentComboBoxPanel = new JPanel();
componentComboBoxPanel.setMaximumSize(new Dimension(600, 25));
componentComboBoxPanel.setLayout(new BoxLayout(componentComboBoxPanel, BoxLayout.X_AXIS));
JLabel componentLabel = new JLabel("Component Plane Option: ");
componentComboBoxPanel.add(componentLabel);
JComboBox<String> componentComboBox = new JComboBox<String>();
componentComboBoxPanel.add(componentComboBox);
for(int i = 0; i < optimalMaps.length; i++){
componentComboBox.addItem(optimalMaps[i].getTypeOfData());
optimalMaps[i].initComponentPlanes();
}
JPanel outerPan = new JPanel();
outerPan.setLayout(null);
java.awt.event.ItemListener itemListener = new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent itemEvent) {
if (itemEvent.getStateChange() == java.awt.event.ItemEvent.SELECTED) {
int indexSelected = componentComboBox.getSelectedIndex();
System.out.println("ind:" + indexSelected);
outerPan.removeAll();
for(int i = 0; i < optimalMaps[indexSelected].getComponentPlanes().length; i++){
JPanel pan = new JPanel () ;
pan.setLayout(null);
pan.add(optimalMaps[indexSelected].getComponentPlanes()[i]);
pan.setBorder(javax.swing.BorderFactory.createTitledBorder(
optimalMaps[indexSelected].getInputData().getVariableLabels()[i]));
pan.setBounds(240*(i%4),(280*(i/4)),240,280);
pan.setToolTipText(optimalMaps[indexSelected].getInputData().getVariableLabels()[i]);
outerPan.add(pan);
}
outerPan.setPreferredSize(new Dimension(240*4, 280*(optimalMaps[indexSelected].getSOMTrainer()
.getLattice().getNumberOfNodeElements()/4 + 1)));
outerPan.revalidate();
outerPan.repaint();
}
}
};
componentComboBox.addItemListener(itemListener);
panelScroll.add(componentComboBoxPanel);
panelScroll.add(outerPan);
componentComboBox.setSelectedIndex(-1);
componentComboBox.setSelectedIndex(0);
//return null;
done();
}
protected void done(){
scrollPane.setViewportView(panelScroll);
for(int i = 0; i < finalVisualizationTabPane.getTabCount(); i++){
if(finalVisualizationTabPane.getTitleAt(i).equals("Component Planes"))
finalVisualizationTabPane.remove(i);
}
finalVisualizationTabPane.add("Component Planes", scrollPane);
finalVisualizationTabPane.setSelectedIndex(finalVisualizationTabPane.getTabCount() - 1);
finalVisualizationPanel.revalidate();
finalVisualizationPanel.repaint();
componentDone = true;
visLogger.throwSuccessMessage("Component Planes Visualization completed! \n");
}
}
I have tried using SwingWorker instead of traditional Thread but it is almost the same. It LAGS and FREEZES on a large N halfway through.
This is the code triggered/called by "optimalMaps[i].initComponentPlanes();" from the above code
public void initComponentPlanes(){
componentPlanes = new ComponentPlane[somtrainer.getLattice().getNumberOfNodeElements()];
int size = somtrainer.getLattice().getNumberOfNodeElements();
for(int i = 0; i < size; i++){
System.out.println(i + ": " + inputData.getVariableLabels()[i] + " size : " + size);
componentPlanes[i] = new ComponentPlane(somtrainer.getLattice(), i);
componentPlanes[i].setBounds((240 - 225)/2, (280-240)/2, 225, 240);
componentPlanes[i].setOrigMaxMin(maxMin[i][0], maxMin[i][1]);
//if(i % 100 == 0) System.gc();
}
}
I would also show you the ComponentPlane.class. I have also tried making ComponentPlane.class a runnable class and try to use componentPlanes[i].run() in the code above but yields almost the same result. Here is the code for the Component Class
public class ComponentPlane extends JPanel{
private Lattice lattice;
private int componentNumber;
private double minValue;
private double maxValue;
private double origMinValue;
private double origMaxValue;
public ComponentPlane(Lattice lattice, int componentNumber){
this.lattice = new Lattice();
this.componentNumber = componentNumber;
initLattice(lattice);
initComponentPlane();
}
private void initLattice(Lattice lattice){
this.lattice.setLatticeHeight(lattice.getLatticeHeight());
this.lattice.setLatticeWidth(lattice.getLatticeWidth());
this.lattice.setNumberOfNodeElements(lattice.getNumberOfNodeElements());
this.lattice.initializeValues();
for(int i = 0; i < this.lattice.getTotalNumberOfNodes(); i++){
this.lattice.getLatticeNode()[i] = new Node(lattice.getLatticeNode()[i]);
}
this.lattice.setNodeHeight(lattice.getNodeHeight());
this.lattice.setNodeWidth(lattice.getNodeWidth());
this.lattice.setTotalNumberOfNodes(lattice.getTotalNumberOfNodes());
}
public Lattice getLattice(){
return lattice;
}
private void initComponentPlane(){
maxValue = lattice.getLatticeNode()[0].getDoubleElementAt(componentNumber);
minValue = lattice.getLatticeNode()[0].getDoubleElementAt(componentNumber);
for(int i = 1; i < lattice.getTotalNumberOfNodes(); i++){
if(lattice.getLatticeNode()[i].getDoubleElementAt(componentNumber) <
minValue){
minValue = lattice.getLatticeNode()[i].getDoubleElementAt(componentNumber);
}
if(lattice.getLatticeNode()[i].getDoubleElementAt(componentNumber) > maxValue){
maxValue = lattice.getLatticeNode()[i].getDoubleElementAt(componentNumber);
}
}
for(int i = 0; i < lattice.getTotalNumberOfNodes(); i++){
Node currNode = lattice.getLatticeNode()[i];
int colorValue = (int)Math.round((currNode.getDoubleElementAt(componentNumber)
- minValue) / (maxValue - minValue) * 1020);
Color nodeColor = new Color(0);
int caseValue = colorValue/256;
if(caseValue == 0)
nodeColor = new Color(0, (colorValue % 256), 255);
else if(caseValue == 1)
nodeColor = new Color(0, 255, 255 - (colorValue % 256));
else if (caseValue == 2)
nodeColor = new Color((colorValue % 256), 255, 0);
else nodeColor = new Color(255, 255 - (colorValue % 256), 0);
lattice.getLatticeNode()[i].setNodeColor(nodeColor);
}
}
public double getMaxValue(){
return maxValue;
}
public double getMinValue(){
return minValue;
}
public void setOrigMaxMin(double maxValue, double minValue){
this.origMaxValue = this.maxValue * (maxValue - minValue) + minValue;
this.origMinValue = this.minValue * (maxValue - minValue) + minValue;
}
public void paintComponent(Graphics g){
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
g2.scale(0.5, 0.5);
for(int i = 0; i < lattice.getTotalNumberOfNodes(); i++){
g.setColor(lattice.getLatticeNode()[i].getNodeColor());
g.fillRect(lattice.getLatticeNode()[i].getxPos() - lattice.getNodeWidth() /2,
lattice.getLatticeNode()[i].getyPos() - lattice.getNodeHeight() /2
, lattice.getNodeWidth(), lattice.getNodeHeight());
g.setColor(Color.BLACK);
g.drawRect(lattice.getLatticeNode()[i].getxPos() - lattice.getNodeWidth() /2,
lattice.getLatticeNode()[i].getyPos() - lattice.getNodeHeight() /2
, lattice.getNodeWidth(), lattice.getNodeHeight());
}
g.setColor(Color.BLACK);
double hund = 100;
int intMaxValue = (int) (origMaxValue*hund);
int intMinValue = (int) (origMinValue*hund);
g.setFont(new Font("Arial", Font.PLAIN, 18));
g.drawString(Double.toString(intMinValue/hund), 0, 470);
g.drawString(Double.toString(intMaxValue/hund), 405, 470);
for(int i = 0; i < 1024; i++){
if(i < 256) g.setColor(new Color(0, (i % 256), 255));
else if(i < 512) g.setColor(new Color(0, 255, 255 - (i % 256)));
else if(i < 768) g.setColor(new Color((i % 256), 255, 0));
else g.setColor(new Color(255, 255 - (i % 256), 0));
double width = 350;
g.fillRect((int)Math.ceil(i * width/1024) + 50, 455, (int)Math.ceil(width/1024), 15);
}
g.setColor(Color.BLACK);
g.drawRect(50, 455, 350, 15);
}
}
Also, sometimes, I get this error when I wait too long after it FREEZES halfway... Exception in thread "Image Fetcher 0" java.lang.OutOfMemoryError: Java heap space at java.awt.image.DataBufferInt.(DataBufferInt.java:75) at java.awt.image.Raster.createPackedRaster(Raster.java:467) at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1032) at sun.awt.image.ImageRepresentation.createBufferedImage(ImageRepresentation.java:253) at sun.awt.image.ImageRepresentation.setPixels(ImageRepresentation.java:559) at sun.awt.image.ImageDecoder.setPixels(ImageDecoder.java:138) at sun.awt.image.JPEGImageDecoder.sendPixels(JPEGImageDecoder.java:119) at sun.awt.image.JPEGImageDecoder.readImage(Native Method) at sun.awt.image.JPEGImageDecoder.produceImage(JPEGImageDecoder.java:141) at sun.awt.image.InputStreamImageSource.doFetch(InputStreamImageSource.java:269) at sun.awt.image.ImageFetcher.fetchloop(ImageFetcher.java:205) at sun.awt.image.ImageFetcher.run(ImageFetcher.java:169)
Sorry for the lengthy post. I am in dire need of your help. Thank you.