Results 21 to 28 of 28
Thread: Performance problem
- 09-10-2009, 11:24 AM #21
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
- 09-10-2009, 12:42 PM #22
Member
- Join Date
- Sep 2009
- Posts
- 8
- Rep Power
- 0
Sorry but I'm at work right now, and the boss would kill me if he know that I'm not working :D
I removed finalize and I don't get any leaks about them...
mysql-connector-java-5.1.8-bin.jarAlso, which MySQL driver are you using?
hm... how to check this?How much memory have you got assigned to your JVM when you run this?
connection classOK, let's start with the db side. Show how you're getting and releasing connections, statements and resultsets.
SELECT... I call this select from other classJava Code:public class ClientSQLConnect { static String[][] sPolja; static EkranClient client; public static String[][] Select(int iSize, String select) { try { povezi(); s.executeQuery (select); ResultSet rs = s.getResultSet(); int size = count(rs); sPolja = new String[size][iSize]; rs.beforeFirst(); int i = 0; while (rs.next()) { for (int j = 1; iSize+1 > j; j++) { sPolja[i][j-1] = rs.getString(j); } i++; } rs.close ( ); // close result set s.close ( ); // close statement if (conn != null) { try { conn.close ( ); } catch (Exception e) { /* ignore close errors */ } } } catch (Exception e) { System.err.println ("CLIENT: Cannot connect to server "+e); //ponovnoPovezi(); } return sPolja; } public static void Update(String update) { // try { povezi(); s = conn.createStatement(); s.executeUpdate(update); s.close ( ); // close statement if (conn != null) { try { conn.close ( ); } catch (Exception e) { /* ignore close errors */ } } } catch (Exception e) { System.err.println ("CLIENT: Cannot connect to server "+e); } } static Connection conn = null; static Statement s = null; public static Statement povezi() { ClientStart start = new ClientStart(); String url = start.connect()[0]; String userName = start.connect()[1]; String password = "xxxxxx"; try { Class.forName(start.connect()[2]).newInstance(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } try { conn = DriverManager.getConnection(url, userName, password); } catch (SQLException e) { e.printStackTrace(); } try { s = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); } catch (SQLException e) { e.printStackTrace(); } return s; } public static int count(ResultSet rs){ int rows = 0; try { rs.last(); rows = rs.getRow(); } catch (SQLException e) { e.printStackTrace(); } return rows; } }
Java Code:public class ClientSQLSelect { static Object[][] sqlData = null; static String sqlSelect = ""; public static Object[][] getParametri(){ sqlSelect = " SELECT id, vr_int, vr_str, opis FROM normo.parametri "; sqlData = ClientSQLConnect.Select(4, sqlSelect); return sqlData; } }Last edited by varann; 09-10-2009 at 01:44 PM.
- 09-10-2009, 12:47 PM #23
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
close connections in a finally block.
finally != finalize
- 09-10-2009, 01:04 PM #24
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
As r035198x says, finalize is not the same as the finally bit of a try/catch. Anyway, do as they say and close resource in a finally block for the try/catches. Do them in the order rs, s, conn, and wrap each in its own try/catch.
This is unlikely to be your problem, though...could be, who knows right now.
How are you launching it? If it's just "java" on the commad line and you have no "Xmx" option supplied then you're using the default, which is quite low I think. Again, there's no guarantee this is the problem, but the gc might be thrashing occasionally trying to free up space. Try setting it to "-Xmx=256m".
OK for the code, and again much of this is unlikely to be the cure, but tidying things up can help.
There's no need for sPolja to be static. You only use it in the Select() method, so it may as well be local to that method. In addition, I'd use an ArrayList<String[]>. That way you don't have to determine the size of the result set beforehand, which involves reading in the entire result set in one go, rather than streaming it in in batches. I have no idea how big the result set is for this, but it can cause problems. You can always turn it into a String[][] at the end by simply doing toArray().
Why are you rebuilding this each time?
Java Code:ClientStart start = new ClientStart(); String url = start.connect()[0]; String userName = start.connect()[1]; String password = "ad5utij7";
- 09-10-2009, 07:56 PM #25
Member
- Join Date
- Sep 2009
- Posts
- 8
- Rep Power
- 0
Tnx guys for the motivation :)
I have made some severe changes to the code. Removed many stupid things :). Next time I'll be more careful. I'm still not shure if it works, have to wait through the night, but it's much better.
One more question. Since the program should work day and night (not yet, but it should be designed that way) how could I restart it every 12 hours?
Tnx again.
- 09-11-2009, 09:20 AM #26
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Why do you need to restart it?
If it's functioning OK, and not leaking anything, it should merrily keep ticking away.
- 09-11-2009, 09:36 AM #27
Member
- Join Date
- Sep 2009
- Posts
- 8
- Rep Power
- 0
Finally good morning :) After 12 hours it's still working like it should.
Why should I restart it? I'm still not 100% that all leaks are gone... It was just a thought. On Sunday I need to install the program. If a find out that it crashes after few days that's not good :)
Another one... are there any arguments running the java that could help, beside Xmx?
- 09-11-2009, 10:15 AM #28
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Well, take a heap dump every hour or two over today, and maybe again tomorrow. If the heap file gets bigger consistently then you might have a problem. Note, don't restart the program, since you've had it running for 12 hours it should have found its equilibrium, so you'll only see fluctuations rather than a steady increase.
If the sizes of the files don't increase noticeably (they should go up and down a bit depending on whether the dump occurred before or afer a gc()) you should be fine.
If it turns out you do need to restart, that's be the job of an external script, probably.
Other than Xmx, if you now have a value you;re happy with then set Xms to it as well. That is the starting memory for the JVM. Setting them the same saves the JVM from having to grab extra memory as the heap fills up.
Similar Threads
-
Help....Sufferring from Performance realted problem...!
By Shiv in forum AWT / SwingReplies: 1Last Post: 06-05-2009, 11:30 PM -
loop performance (no problem, just investigating)
By CJSLMAN in forum New To JavaReplies: 3Last Post: 01-18-2009, 03:02 AM -
Applet performance problem...
By pmrenaud in forum Java AppletsReplies: 0Last Post: 01-07-2009, 03:47 PM -
performance problem on osx
By coldnebo in forum Advanced JavaReplies: 3Last Post: 08-01-2008, 09:39 PM -
Performance Of Collections
By thomasprabu in forum Advanced JavaReplies: 0Last Post: 01-05-2008, 11:17 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks