Re: reducing JDBC String creation?





Daisy wrote:

With some help from this group, I improved my database throughput quite
a bit.  However, my code now creates a large number of Strings
(approximately 4 million in about 3 minutes) in PreparedStatements.  I
checked the source of String creation with OptimizeIt and Enerjy's
memory profiler.  The primary source of Strings are the
PreparedStatement.setInt() and PreparedStatement.setString() methods.

When I force a garbage collection, these are collected.  However, is
there a way to avoid so much String creation, particularly when writing
ints?  Is there a way to pass the existing int or String to the batch?

No, but there's no harm in the memory use. If the JVM needs memory, it will run gc() and get those strings that are unneeded. You can't tell a driver to use your own string etc, because you might alter it before/while the driver was using it. It will always copy the data, especially if you're doing batches. Joe Weinstein at BEA Systems



class DatabaseWriter{

int writeCount=0;

public DatabaseWriter(){

  PreparedStatement preparedStatement =
connection.prepareStatement("insert into       msgpersecond ( time ,
count ) values ( ? , ?  )");

  connection.setAutoCommit( false ); // turn off auto-Commit

}

public void process(Object input){

  preparedStatement.setLong( 1 , event.longVar );
  preparedStatement.setString( 2 , event.stringVar );
  preparedStatement.addBatch( );
  writeCount++:

  if (writeCount > 50) {
    updateCounts = preparedStatement.executeBatch( );
    connection.commit( );

preparedStatement.clearBatch( );
writeCount=0;
}


}
}


process() gets called a lot.

Thanks


.



Relevant Pages

  • Re: Cant add a usb Cannon i960 printer
    ... the printer gets defined with a device string like the ... it is hardly interesting to repeat it unless the usblp kernel driver ... >and then the kernel discovers its devcies as it enumerates and probes buses. ...
    (comp.os.linux.setup)
  • Access web cam with multiple web cams
    ... tuner seem to use the same driver ... Private Const WS_VISIBLE As Integer = &H10000000 ... (ByVal lpszWindowName As String, ByVal dwStyle As Integer, ByVal x As ... Dim DriverVersion As String = Space ...
    (microsoft.public.dotnet.languages.vb)
  • AddPrinter in Windows 98
    ... Public Type PRINTER_DEFAULTS ... (ByVal pName As String, ByVal Level As Long, pPrinter As PRINTER_INFO_2) ... ' Driver Name - Driver must be installed already ... pi2.pDriverName = AddString(strDriver, bBuffer) ...
    (microsoft.public.vb.winapi)
  • Re: Is C# support load device driver?
    ... how to manage driver loading/unloading using both PInvoke interop and WMI. ... string driverName; ... IntPtr fileHandle; ... databaseName, uint dwDesiredAccess); ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Is C# support load device driver?
    ... I can see my driver is loaded. ... > string driverName; ... > internal static extern IntPtr OpenSCManager(string machineName, ... > uint dwDesiredAccess, uint serviceType, uint startType, uint ...
    (microsoft.public.dotnet.languages.csharp)