Memory leak with jsp and beans
The application we have created has one particular page that is designed to stay up in the browser and refresh with new information from database queries once every 60 seconds. Running with Tomcat3.2.1 and IE5.5
The problem is that the memory usage of java.exe continues to grow until the machine crashes from out of memory. It does take more than 24 hours to crash.
Things I have tried to do to track down the problem or eliminate the problem.
- I have explicitly set the scope of the beans to "page"
- I have watched the DatabaseAccess.class (the beans are all extended from this class) and put in code to watch how many instantiations of the class are made and subsequently garbage collected. This appears to be where the memory leak may reside - hundreds of instantiations from some other source than the page I am displaying.
- the top frame makes database queries for security and display of a menu system dependant upon security clearance. It does not set any time for refresh (refresh == 0). Nor does it explicitly set a scope for the beans.
- I have run a different jsp engine to see if this was directly related to Tomcat - same problem with resin2.0.0
The main jsp page that is in the bottom section of the page has the following code:
** only the relevant lines are included here
<%@ include file="../../common.jsp" %>
<%
refresh=60;
%>
<head>
<%@ include file="../../meta_head.jsp" %>
</head>
<body bgcolor="#FFFFFF" text="#003399" link="#660099" vlink="#990099" alink="#006666" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<%@ include file="../../access.jsp" %>
<%@ include file="../../page_title.jsp" %>
<jsp:useBean id="Line" class="jsp.Line" scope="page" />
<jsp:useBean id="Machine" class="jsp.Machine" scope="page"/>
<jsp:useBean id="Alarm_log" class="jsp.Alarm_log" scope="page"/>
contents of meta_head.jsp
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<META HTTP-EQUIV= "expires" content = "0">
<META HTTP-EQUIV="Pragma" CONTENT="no_cache">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache" forua="true">
<META NAME="robots" content="NOINDEX,NOFOLLOW">
<%
if (refresh > 0)
%>
<meta http-equiv="Refresh" content="<%= refresh %>">
<%
If anyone has some suggestions on how to trap this memory leak, it would be terrific. Or, some other things to try to stop the instantiation of the DatabaseAccess object (perhaps setting the scope of the beans in the header to "session" or "application"?).
Thanks in advance.
Roberta
jsp:useBean tags scope declaration :
page = Create a new instance on each load.
session = Load instance from the session, if not there, create one
application = Load instance from the ServletContext, if not there, create one.
Not sure how you are populating the data variables, but make sure you are closing all ResultSet, (Prepared)Statement, and Connection objects.
Similar Messages
-
Memory leak with fieldpoint and labview
I have an application which is showing an issue of a memory leak. The application does several things, but the part that seems to be causing the trouble is related to use of Fieldpoint VIs. The application reads individual AI channels on a Fieldpoint AI-110 (10 channels, where the set of channels is measured once per second) I have attached the code related to this. The memory leak is quite large (~1.5GB in 24 hours of operation).
I am using LabView 7.1, and Fieldpoint 4.1. The parent application which uses the attached code is a stand-alone application. The operating system is Windows 2000. Fieldpoint communication occurs over a RS-232 link.
Thanks in advance,
Andy
Attachments:
FPAI100_meas_voltage.vi 62 KBHi Andy,
I did not see anything fundamentally wrong with what you wrote, but there were
a few things that I think could be used to be changed. However, there
were a few things that I did modify that might make a bit of a
difference. In your application you were using sequences and a bunch of
local variables. Since LabVIEW is based upon data flow, you can control
the sequence of execution by making data dependencies and simply wiring one
thing to the next. By simply using LabVIEW the way it is meant to run I
was able to completely remove the sequence structure and also eliminate the use
of all of the local variables, all while having the exact same execution order.
It could be that the local variables were causing the memory leak that you
noticed, but I really doubt they could be the cause of such a large leak.
I really think there is probably something else going on in the application
because from what I saw from this bit of code there really is no way that it
would have such large problems. Users use the FP commands daily without
any problems, so most likely these are not the root of the problem.
Go ahead and try the modified code and see if you can implement similar local
and global variable reducing techniques throughout your application.
Hopefully that will help reduce some of the memory leaks you are seeing.
Typically the largest cause of an apparent memory leak really occurs from
building an array within a loop, so make sure you don't have any situations
where that occurs in your code either.
Regards,
Otis
Training and Certification
Product Support Engineer
National Instruments
Attachments:
724727-FPAI100_meas_voltage.vi 56 KB -
Memory leaks with Njawin and COm Object
I'm using njawin 1.1 to use a DRM Microsoft object form java and all works
very well .... very good bridge !!
But I found a problem that seems like a "memory leak" in calling a method,
in this lines code :
myLicense = myLicenseObj.GetLicenseToDeliver();
System.out.println(myLicense);
myResponseObj.AddLicense("2.0.0.0", myLicense);
myResponseObj.setReplaceQuotesWith("\\\"");
myLicResponse = myResponseObj.GetLicenseResponse();
The only particularity in this code the length of myLicense string : 7 KB
If I run the program 1000 times the server use 100 Mb of ram and not release
them.
I try to use ASP to replicate the problem but nothing happens ... the
program works and not memory leak appears and than I think taht the probelm
may be in marshalling / unmarshalling string routine from/to the DRM object
Thanks a lot for all helpMe funciono colocando el progID de la interfaz que genero jawin en el constructor de la clase que se genero, despues utilice los metodos y fue transparente:
Interfaz que genero jawin:::
public interface CodeIMG {
public static final GUID clsID = new GUID("{23435XCVDF2-6D62-6749- 8E00-00AS45GH87JU}");
public static final String progID = new String("ActivexPDF.CodeIMG");
la clase que genero jawin:::::::
public class _CodeWER extends DispatchPtr {
public int getTypeInfoToken() {
return 0;
static public final GUID proxyIID = new GUID("{632PHK77-6F0B-11D4-8PLD-00A024A31CC6}");
static public final int iidToken;
static {
iidToken = IdentityManager.registerProxy(proxyIID, _CodeWER.class);
public int getGuidToken() {
return iidToken;
* Creates empty _CodeWER Object
public _CodeWER() throws COMException {
super();
* Creates _CodeWER() Object with progID
public _CodeWER()(String progid) throws COMException {
super(progid);
* Queries interface of _CodeWER Object
public _CodeWER()(IUnknown other) throws COMException {
super(other);
* Creates _CodeWER() Object with CLSID
public _CodeWER(GUID ClsID) throws COMException {
super(ClsID);
public boolean createImg(ObjectRef strChain, ObjectRef strFile) throws COMException {
return ((java.lang.Boolean) invokeN("createImg", new Object[]{strChain, strFile}, 2)).booleanValue();
Test de Prueba:::::::
public class TestDLL implements CodeIMG {
public static void main(String[] args) {
try {
CodeWER pdf = new CodeWER ( clsID );
boolean ok = pdf.createImg(new ObjectRef("9999999"), new ObjectRef("C:\\image.bmp") );
System.out.println("Lo generoi bien:: " + ok );
} catch (COMException e) {
e.printStackTrace();
Espero te sirva este ejemplito sencillo de jawin
Saludos!!!!!!!!!!!!
att juo -
Please recommend IDE for JSP and Beans
Hi guys,
I am looking for a decent IDE to work with JSP and Beans. I have tried JBuilder which has too much going on at the same time and I find it to be an overkill for what I am doing; I find NetBeans kind of irritating. I develop web applications, hence I dont need any GUI stuff for beans.
Just looking for something that will enable me to rapidly develop beans as a support system for JSP pages and at the same time, it should provide good support for coding JSP pages. Little bit of management functions wont hurt either, but are not required. I dont mind if I have to pay for the IDE. Any recommendations?I like Eclipse for Java Development, and I use the MyEclipse plug-in for J2EE development.
There is a free J2EE plug-in (Lomboz) but I'd much rather pay the $29.99/year for MyEclipse. It's been perfect for me. -
It seems there is a memory leak with JPopupMenu. The following program demonstrates this leak. If you run the program, click on show form, and then close the form, the used memory will be GCd appropriately. If you click on show form, then right click on the table to show the popup (even if you dont do anything else with the popup) then close the form, it never GCs the form. I've tried all kinds of crazy things, but I cant seem to find what is keeping the memory from being GCd.
Peter
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.beans.PropertyChangeListener;
import java.text.DecimalFormat;
import java.util.Timer;
import java.util.TimerTask;
import java.util.Vector;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.table.AbstractTableModel;
@SuppressWarnings("serial")
public class TriState extends JPanel {
private static final long K = 1024;
private static final long M = K * K;
private static final long G = M * K;
private static final long T = G * K;
protected static int ctr = 1;
private JButton btnShow = new JButton("Show Form");
private JLabel lblMem = new JLabel();
private static final DecimalFormat df = new DecimalFormat("#,##0.#");
protected Timer updateTimer = new Timer();
public TriState() {
this.setLayout(new GridLayout());
add(btnShow);
add(lblMem);
updateTimer.scheduleAtFixedRate(new UpdateTimerTask(), 1000, 1000);
btnShow.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
FrmReferrals fr = new FrmReferrals();
fr.setVisible(true);
class UpdateTimerTask extends TimerTask {
public void run() {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
dumpMemoryUsage();
protected void dumpMemoryUsage() {
System.gc();
Long t = Runtime.getRuntime().totalMemory();
long f = Runtime.getRuntime().freeMemory();
String st = convertToStringRepresentation(t);
String sf = convertToStringRepresentation(f);
String su = convertToStringRepresentation(t - f);
System.out.println("Total:" + st + "(" + t + ") Free:" + sf + "(" + f + ") Used:" + su + "(" + (t - f) + ")");
lblMem.setText(su + "/" + st);
public static String convertToStringRepresentation(final long value) {
final long[] dividers = new long[]{T, G, M, K, 1};
final String[] units = new String[]{"TB", "GB", "MB", "KB", "B"};
if (value < 1)
throw new IllegalArgumentException("Invalid file size: " + value);
String result = null;
for (int i = 0; i < dividers.length; i++) {
final long divider = dividers;
if (value >= divider) {
final double dr = divider > 1 ? (double) value / (double) divider : (double) value;
result = df.format(dr) + units[i];
break;
return result;
private static void createAndShowGUI() {
JFrame frame = new JFrame("SimpleTableDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Create and set up the content pane.
TriState newContentPane = new TriState();
newContentPane.setOpaque(true); // content panes must be opaque
frame.setContentPane(newContentPane);
// Display the window.
frame.pack();
frame.setVisible(true);
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
protected class PopupMenu extends JPopupMenu {
public PopupMenu() {
JRadioButtonMenuItem item1 = new JRadioButtonMenuItem(new AbstractAction("Insert Item") {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println(e.getActionCommand());
item1.setActionCommand("Insert");
add(item1);
JRadioButtonMenuItem item2 = new JRadioButtonMenuItem(new AbstractAction("Delete Item") {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println(e.getActionCommand());
item2.setActionCommand("Delete");
add(item2);
public class FrmReferrals extends JFrame {
public FrmReferrals() {
super();
init();
protected void init() {
jbInit();
protected void closeIt() {
uninit();
// variables here
protected Dimension dimPreferred = new Dimension(1270, 995);
protected JTabbedPane tabbedPane = new JTabbedPane();
protected JTable tblReferrals = null;
protected PopupMenu popMenu = new PopupMenu();
protected void jbInit() {
setPreferredSize(dimPreferred);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setTitle("Referrals");
JPanel pnl = new JPanel();
pnl.setOpaque(false);
pnl.setLayout(new BorderLayout());
pnl.add(tabbedPane, BorderLayout.CENTER);
// put it all in the frame
add(pnl);
pack();
setLocationRelativeTo(null);
// init the table and model
ReferralsTableModel ctm = new ReferralsTableModel(buildDummyVector());
tblReferrals = new JTable(ctm);
tblReferrals.setComponentPopupMenu(popMenu);
tblReferrals.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
tabbedPane.add(new JScrollPane(tblReferrals, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED));
addWindowListener(new WindowListener() {
@Override
public void windowActivated(WindowEvent e) {}
@Override
public void windowClosed(WindowEvent e) {}
@Override
public void windowClosing(WindowEvent e) {
closeIt();
@Override
public void windowDeactivated(WindowEvent e) {}
@Override
public void windowDeiconified(WindowEvent e) {}
@Override
public void windowIconified(WindowEvent e) {}
@Override
public void windowOpened(WindowEvent e) {}
protected Vector<DBO_Referrals> buildDummyVector() {
Vector<DBO_Referrals> vr = new Vector<DBO_Referrals>();
for (int x = 0; x < 5000; x++) {
DBO_Referrals r = new DBO_Referrals(x+(5000*ctr));
vr.add(r);
return vr;
protected void uninit() {
tblReferrals.setComponentPopupMenu(null);
for (Component c : popMenu.getComponents()) {
PropertyChangeListener[] pl = c.getPropertyChangeListeners();
for (PropertyChangeListener l : pl)
c.removePropertyChangeListener(l);
if (c instanceof JMenuItem) {
ActionListener [] al = ((JMenuItem)c).getActionListeners();
for (ActionListener l : al) {
((JMenuItem)c).removeActionListener(l);
popMenu = null;
protected class DBO_Referrals {
protected long id;
protected String Employee;
protected String Rep;
protected String Asst;
protected String Client;
protected String Dates;
protected String Status;
protected String Home;
public DBO_Referrals(long id) {
this.id = id;
Employee = "Employee" + id;
Rep = "Rep" + id;
Asst = "Asst" + id;
Client = "Client" + id;
Dates = "Dates" + id;
Status = "Status" + id;
Home = "Home" + id;
public long getId() {
return id;
public String getEmployee() {
return Employee;
public String getRep() {
return Rep;
public String getAsst() {
return Asst;
public String getClient() {
return Client;
public String getDates() {
return Dates;
public String getStatus() {
return Status;
public String getHome() {
return Home;
public class ReferralsTableModel extends AbstractTableModel {
protected Vector<DBO_Referrals> data = new Vector<DBO_Referrals>();
protected String[] sColumns = {"id", "Employee", "Rep", "Assistant", "Client", "Date", "Status", "Home", "R"};
public ReferralsTableModel() {
super();
public ReferralsTableModel(Vector<DBO_Referrals> data) {
this();
this.data = data;
@SuppressWarnings("unchecked")
@Override
public Class getColumnClass(int col) {
switch (col) {
case 0 :
return Long.class;
default :
return String.class;
@Override
public int getColumnCount() {
return sColumns.length;
@Override
public int getRowCount() {
return data.size();
@Override
public Object getValueAt(int row, int col) {
if (row > data.size())
return null;
DBO_Referrals a = data.get(row);
switch (col) {
case 0 :
return a.getId();
case 1 :
return a.getEmployee();
case 2 :
return a.getRep();
case 3 :
return a.getAsst();
case 4 :
return a.getClient();
case 5 :
return a.getDates();
case 6 :
return a.getStatus();
case 7 :
return a.getHome();
case 8 :
return "+";
default :
return null;BTW instead of continually printing out the memory use a profiler (jvisualvm in the jdk/bin directory -> heapdump -> search on your class -> view in instances -> find nearest GC root).
Looks like BasicPopupMenuUI doesn't remove a reference to the JRootPane immediately. As far as I can see it will be removed when another menu shows.
As a hackish workaround you can try this in you FrmReferrals#uninit():
for(ChangeListener listener : MenuSelectionManager.defaultManager().getChangeListeners()) {
if (listener.getClass().getName().contains("MenuKeyboardHelper")) {
try {
Field field = listener.getClass().getDeclaredField("menuInputMap");
field.setAccessible(true);
field.set(listener, null);
} catch (Exception e) {
// ignored
break;
}Funnily enough though it isn't there when I reduce your code to a SSCCE:
import java.awt.*;
import javax.swing.*;
public class TestBasicPopupMenuUILeak extends JFrame {
public TestBasicPopupMenuUILeak() {
super("Not collected right away");
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
JFrame frame = new JFrame("Test");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.getContentPane().add(
new JButton(new AbstractAction("Show frame") {
@Override
public void actionPerformed(ActionEvent e) {
EventQueue.invokeLater(new Runnable() {
public void run() {
JLabel label = new JLabel(
"Right click to show popup, then close this frame."
+ "The frame with not be GCed until another (popup) menu is shown.");
JPopupMenu popup = new JPopupMenu(
"Popup");
popup.add("Item");
label.setComponentPopupMenu(popup);
// named differently so you can find it
// easily in your favorite profiler
JFrame frame = new TestBasicPopupMenuUILeak();
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.getContentPane().add(label);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
} -
Memory leaks with Third party classes
Hello all,
This is fairly known problem. But I guess, my problem gives a new dimention to the problem.
I have an application which is developed by me. This application ideally needed to use third party classes ( obviously no source code is supplied ). These third party classes provide extra functionality required.
The problem is, when I don't use third party classes in my application, every thing is fine. When I include third party classes, I am having memory leaks.
Then I tried to investigate memory leaks with Optimizeit tool. It is new to me. As of now, I understood, we can identify where the memory leaks are occuring.
finally the problem is, in order to solve this, I need some patches in the code. But I don't have source code for those classes. How to solve this problem?
For example,
I use a third party classes in my code like this,
ThirdPartyMemoryLeakClass obj = new ThirdPartyMemoryLeakClass();
This 'obj' is made static, as it takes lot of time to create this object. Obviously this object contains several references to other objects, which I can't control.
In the process of reusing this object, I am getting memory leaks.
Any ideas regarding, how one has to deal this type of situations? What are the issues involved with this case? Are there any similar problems, which have been solved? are most welcome.
many thanks for your time.
MadhavDecompile it using jad. Find leak.Yes, I too got the idea and tried to decompile those classes and recompile. I had some problems while recompiling. Is this is the only way to get rid of this problem?
I was refering to powersoft.datawindow.DataStore class. Does any body here has worked on these?
Can you suggest me how to find the memory leak causes? if you were needed to find out memory leak causes, what would be your approach?
Madhav -
Memory leak with 1.6.0_07 in applet using Swing
Java Plug-in 1.6.0_07
Using JRE version 1.6.0_07 Java HotSpot(TM) Client VM
Windows XP - SP2
I have a commercial application that has developed a memory leak with the introduction of the latest plugin. The applets chew up memory and eventually freeze. They did not before. Using jvisualm I see a build up of native arrays, primarily int[][] and char[]. I'm still investigating. Anyone have a similar experience?
The Applet uses a swing interface, uses buffered images and swing timers, and regularly performs http connections to the server which result in actions via the SwingUtil.invokeLater() method.I am Using Internet Explorer Browser Version 6.0.Huge security hole.
Its not throwing Error / Exception Wrap a try/catch at the highest level possible.
Catch 'Throwable'. And log/display it somewhere. -
Help with JSP and logic:iterate
I have some queries hope someone can help me.
I have a jsp page call request.jsp:
====================================
<%@ page import="java.util.*" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<html>
<body>
<%@ page import="RequestData" %>
<jsp:useBean id="RD" class="RequestData" />
<%Iterator data = (Iterator)request.getAttribute("Data");%>
<logic:iterate id="element" name="RD" collection="<%=data%>">
<jsp:getProperty name="RD" property="requestID" />
<%=element%><br>
</logic:iterate>
</body>
</html>
And I have the RequestData.java file:
======================================
private int requestID = 1234;
public int getRequestID() { return requestID; }
The jsp page display:
======================
0 RequestData@590510
0 RequestData@5b6d00
0 RequestData@514f7f
0 RequestData@3a5a9c
0 RequestData@12d7ae
0 RequestData@e1666
Seems like the requestID is not returned. Does anybody know this?
I have done the exact one using JSP and servlets, trying to learn using JSP and custom tags. The one with JSP and servlet looks like:
============================================
<%@ page import="RequestData" %>
<%Iterator data = (Iterator)request.getAttribute("Data");
while (data.hasNext()) {
RequestData RD = (RequestData)data.next();
out.println(RD.getRequestID() );
}%>Oh think I got it...
but one thing I'm not sure is...
If I use "<jsp:useBean id="RD" class="RequestData" />", do I still need "<%@ page import="RequestData" %>"?
I tried without and it gives me error... -
Still memory leaks with 10.8.4
I hoped 10.8.4 could solve the issue..
Unfortunately I still have memory leaks, pages out and inactive memory full for a lot of programs running. First of all FCX importing and transcoding full the inactive memory, and OSX slows down, swapping to the SSD. The same problem with all (4 in total) macs mounting ML.
Has anyone solved the problem please?
Thanks in advance.
AttilioAttilio, although I'm not a Final Cut user, I suspect that your problem is, as Kappy first said - insufficient RAM.
See: http://forums.macrumors.com/showthread.php?t=1332888 for instance.
It's a RAM hog. With the Retina, you're stuck with the RAM you've got now, unfortunately. With any other hardware, I'd consider boosting the RAM as much as you can. I don't run FCX or any video editing software (I build web sites - so I use Dreamweaver, Photoshop, Lightroom etc.) and I boosted the RAM in my Mac Pro to 18GB quite a while ago because I was seeing a lot of pageouts and slowdowns with 10GB. I do tend to have a ton of windows and apps open at once.
See also: https://discussions.apple.com/thread/4759586?start=0&tstart=0 - Kappy's very good explanation of memory usage and various links to check.
Whether it appeared to run better in SL or not, I can't really say - unless you ran two identical Macs, side by side doing exactly the same things in FCX with the two operating systems installed, I don't know how one could accurately assess that. -
Hi guys Pls tell me a way to connect db4 database with jsp and which driver
hi guys
Pls tell me a way to connect db4 database with jsp and
also tell me which driver i have to use
also tell me how to connect with excel sheetstake a look at the follwing links. There, you'll find all what you need :
DB4:
http://www.oracle.com/database/berkeley-db/je/index.html
http://www.oracle.com/technology/products/berkeley-db/je/index.html
http://www.oracle.com/database/berkeley-db/db/index.html
http://www.oracle.com/database/docs/berkeley-db-je-datasheet.pdf
Excel:
http://64.18.163.122/rgagnon/javadetails/java-0516.html
Hope That Helps -
Memory leak with UI automation
Hi,
I noticed there is memory leak with UI automation in my window 8.1.
I noticed there is solution for window 8
http://support.microsoft.com/kb/2885482
Is there any solution for window 8.1?
I really appreciate for any help.Hi,
I'm sorry for didn't hear anything about this issue. I'll try to connect the writer of this KB, hope we can find some suggestion. If there is any progress about this problem, I would come back.
Roger Lu
TechNet Community Support -
Possible causes for memory leak in Java and Tomcat
I would like to enquire what are the typical mistakes done by programmers that will cause memory leak in Java and Tomcat.
Please refer the below site. It will give more points about the memory leak and how to rectify it.
http://www.experts-exchange.com/Software/Server_Software/Application_Servers/Q_20981562.html?cid=336 -
Problems with JSP and MySql bean.
Hi,
I'm new to JSP and I'm having some problems with it. I'm trying to do a simple login where a java class (bean?) handles the SQL injektion. I have deployed the page on tomcat and it works fine, except that the sqlinjektion does basically nothing. I have installed the mysql driver. I think there is something wrong with the java class, or the way im calling it. It does not produce any error. But its like it would never actually process the java code, because ive tried to append things to error string to see what is going on, nothing happens. everything stay null, no exceptions are thrown. If I implement the code to JSP itself, it does load the driver and print exception that there is no connection to database (which is correct). What am I missing? Code follows:
the sqlhandler:
public abstract class SqlInjektor {
private static String Database = "*****";
private static String serverName = "localhost:3306";
private static String usrName="******";
private static String passw="******";
* @return Connection
public static Connection createConnection(String error){
Connection mySqlCon = null;
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
catch(Exception E){
PrintWriter out = response.getWriter();
out.println("lol");
String url = "jdbc:mysql://" + serverName + "/" + Database + "?user=" + usrName + "&password=" + passw;
try{
mySqlCon = DriverManager.getConnection(url);
catch (Exception E){
E.printStackTrace(System.out);
return mySqlCon;
* Metodi saa sy�tteen��n SQL komennon, jonka se suorittaa sek� palauttaa komennon tulokset.
* @param command
* @return ResultSet
public static ResultSet querySQL(String command,String error, Connection con){
ResultSet rs = null;
try{
Statement stmt = con.createStatement();
rs = stmt.executeQuery(command);
catch(Exception E){
E.printStackTrace(System.out);
return rs;
the jsp page:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page isErrorPage="false" %>
<%@ page import="java.sql.*" %>
<%@page import="ot3.User"%>
<%@page import="ot3.SqlInjektor"%>
<%@page import="Javax.servlet.jsp.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>vastaanotto</title>
</head>
<body>
<%! String id;
String password;
String error = new String("Error!\n");
User user;
%>
<% user = new User();
session.putValue("currentUser",user);
id = request.getParameter("authName");
password = request.getParameter("Password");
Connection conn=null;
ResultSet rs=null;
conn = SqlInjektor.createConnection(error);
if(conn!=null){
out.println("conn ok!");
rs = SqlInjektor.querySQL("SELECT * FROM user WHERE id='" + id +"' AND password='" + password+"' COLLATE latin1_bin;",error,conn);}
try {
if (rs!= null && rs.next()){
user.setID(rs.getInt("id"));
user.setName(rs.getString("name"));
user.setPassword(rs.getString("password"));
user.setClearance(rs.getInt("clearance"));
if(rs.getString("addedby")!=null)
user.setAdder(rs.getInt("addedby"));
if(rs.getString("lastmodifier")!=null)
user.setModifier(rs.getInt("lastmodifier"));
rs.close();%>
ONNISTU!
<%}
else {
out.println(error);
} catch (SQLException e) {
out.println(e.getMessage());
}%>
</body>
</html>Hi,
I'm new to JSP and I'm having some problems with it. I'm trying to do a simple login where a java class (bean?) handles the SQL injektion. I have deployed the page on tomcat and it works fine, except that the sqlinjektion does basically nothing. I have installed the mysql driver. I think there is something wrong with the java class, or the way im calling it. It does not produce any error. But its like it would never actually process the java code, because ive tried to append things to error string to see what is going on, nothing happens. everything stay null, no exceptions are thrown. If I implement the code to JSP itself, it does load the driver and print exception that there is no connection to database (which is correct). What am I missing? Code follows:
the sqlhandler:
public abstract class SqlInjektor {
private static String Database = "*****";
private static String serverName = "localhost:3306";
private static String usrName="******";
private static String passw="******";
* @return Connection
public static Connection createConnection(String error){
Connection mySqlCon = null;
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
catch(Exception E){
PrintWriter out = response.getWriter();
out.println("lol");
String url = "jdbc:mysql://" + serverName + "/" + Database + "?user=" + usrName + "&password=" + passw;
try{
mySqlCon = DriverManager.getConnection(url);
catch (Exception E){
E.printStackTrace(System.out);
return mySqlCon;
* Metodi saa sy�tteen��n SQL komennon, jonka se suorittaa sek� palauttaa komennon tulokset.
* @param command
* @return ResultSet
public static ResultSet querySQL(String command,String error, Connection con){
ResultSet rs = null;
try{
Statement stmt = con.createStatement();
rs = stmt.executeQuery(command);
catch(Exception E){
E.printStackTrace(System.out);
return rs;
the jsp page:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page isErrorPage="false" %>
<%@ page import="java.sql.*" %>
<%@page import="ot3.User"%>
<%@page import="ot3.SqlInjektor"%>
<%@page import="Javax.servlet.jsp.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>vastaanotto</title>
</head>
<body>
<%! String id;
String password;
String error = new String("Error!\n");
User user;
%>
<% user = new User();
session.putValue("currentUser",user);
id = request.getParameter("authName");
password = request.getParameter("Password");
Connection conn=null;
ResultSet rs=null;
conn = SqlInjektor.createConnection(error);
if(conn!=null){
out.println("conn ok!");
rs = SqlInjektor.querySQL("SELECT * FROM user WHERE id='" + id +"' AND password='" + password+"' COLLATE latin1_bin;",error,conn);}
try {
if (rs!= null && rs.next()){
user.setID(rs.getInt("id"));
user.setName(rs.getString("name"));
user.setPassword(rs.getString("password"));
user.setClearance(rs.getInt("clearance"));
if(rs.getString("addedby")!=null)
user.setAdder(rs.getInt("addedby"));
if(rs.getString("lastmodifier")!=null)
user.setModifier(rs.getInt("lastmodifier"));
rs.close();%>
ONNISTU!
<%}
else {
out.println(error);
} catch (SQLException e) {
out.println(e.getMessage());
}%>
</body>
</html> -
Memory leak with large files and this code?
Okay, so the following code will not complete.
Basically what I am doing is opening 5 files and generating a PDF document from the already opened Report file, which is renewed prior to the PDF export operation. I left out the general stuff at the start. I am also writing out the location of the PDF to a HTML file, which acts as an index of the exported PDF documents.
I believe it is due to some sort of memory leak issue, but it could be something else or just my code. I have not stepped through this code, but for small file sizes of say less than 40 megs per file, it works fine. For file sizes along these lines:
File 1 = 230 megs
File 2,3 = 26 megs
File 4,5 = 8 megs
it will belch erors at the end of about the 5th iteration through the For loop. It will complete the 5th iteration however. Here are the errors generated:
84 10/26/2006 9:35:15 AM Error:
85 File handle for "W:\TR-2051-2100\TR-2060 - BAS Arctic PTC\Vnom\00-99\VnomCombined00-99\p1.TDM" file is invalid.
(Error no. 6)
86 10/26/2006 9:40:19 AM Error:
87 File handle for "W:\TR-2051-2100\TR-2060 - BAS Arctic PTC\Vnom\00-99\VnomCombined00-99\p2.TDM" file is invalid.
(Error no. 6)
88 10/26/2006 9:45:17 AM Error:
89 File handle for "W:\TR-2051-2100\TR-2060 - BAS Arctic PTC\Vnom\00-99\VnomCombined00-99\p3.TDM" file is invalid.
(Error no. 6)
90 10/26/2006 9:53:07 AM Error:
91 File handle for "W:\TR-2051-2100\TR-2060 - BAS Arctic PTC\Vnom\00-99\VnomCombined00-99\p8.TDM" file is invalid.
(Error no. 6)
92 10/26/2006 10:00:39 AM Error:
93 File handle for "W:\TR-2051-2100\TR-2060 - BAS Arctic PTC\Vnom\00-99\VnomCombined00-99\p9.TDM" file is invalid.
(Error no. 6)
94 10/26/2006 10:01:01 AM Error:Error occured during file creation.
95 10/26/2006 10:01:01 AM Error:
Error in <GM315 Pa...sing.VBS> (Line: 185, Column: 5):
File handle for "W:\TR-2051-2100\TR-2060 - BAS Arctic PTC\Vnom\00-99\VnomCombined00-99\p1.TDM" file is invalid.
(Error no. 6)
For files of a larger size, like:
File 1 = 7500 megs
File 2,3 = 80 megs
File 4,5 = 25 megs
This occurs after about 2-3 iterations through the loop.
see attachment for code.
Attachments:
ForLoopCode.txt 11 KBi am having a similar error randomly inserted in the log
25 10/1/2009 1:58:36 PM Error:
26 File handle for "C:\Program Files\Summitek\Spartan\data\tdm\S Parameter Test $SSN$ 49.TDMS" file is invalid.
(Error no. 6)
and
31 10/1/2009 1:58:37 PM Error:
32 File handle for "C:\Program Files\Summitek\Spartan\www\temp\Test_$SSN$ 49_602313172.pdf" file is invalid.
(Error no. 6)
it doesn't seem to be causing an immediate problem, but i have had several unexplained Diadem lockups.
they occur in log after i use CALL DATAFILELOADSEL and CALL PICpdfexport
help? what does this mean
jim -
Hi,
I am getting a jvm Memory Leak when i try to load and parse XMLs. The version of JDK is 1.4.1_05. Has anyone faced this problem?
Any pointers to this will be very helpful.
Thanks
RajdeepThere is at least one bug associated with xml (although not because of it) which usually makes an appearance in long running applications.
http://forum.java.sun.com/thread.jsp?forum=31&thread=351925
If this is an internal application you could conceivably replace the StringBuffer class yourself to fix this.
Maybe you are looking for
-
I've tried uninstalling, downgrading, upgrading Firefox (from version 17 to Aurora) and still the problem persists! I've shut down firewall, performed malware checks, cleared cache, history and cookies, started in safemode, and still nothing!! 'https
-
how can i make submit to ptogram type F.
-
Syslog Reports not collect Syslog.log file Messages
I am doing a installation on CiscoWorks 3.2. after two three weeks I found my syslog services is not working properly. Once I checked on the syslog.log its updated with the device logs as normal. But when I am going to generate report it's not collec
-
In my phone 4s near the bettery showing one lock sign with round what is this ?
in my phone 4s near the bettery sign showing one lock sign with round what is this ?
-
Error in account determination: table T030R key INT ZAS
Hello Gurus... im facing a error when i tried for invoice verification using Tcode MIRO i heard its strong issue of FI Error in account determination: table T030R key INT ZAS Error is <b>Error in account determination: table T030R key INT ZAS Message