Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 54361b4

Browse files
committed
High memory usage
Here is a patch which inspired by Michael Stephens that should work Dave Cramer
1 parent 06f6404 commit 54361b4

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/interfaces/jdbc/org/postgresql/jdbc2/PreparedStatement.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
4141

4242
// We use ThreadLocal for SimpleDateFormat's because they are not that
4343
// thread safe, so each calling thread has its own object.
44-
private ThreadLocal tl_df = new ThreadLocal(); // setDate() SimpleDateFormat
45-
private ThreadLocal tl_tsdf = new ThreadLocal(); // setTimestamp() SimpleDateFormat
44+
private static ThreadLocal tl_df = new ThreadLocal(); // setDate() SimpleDateFormat
45+
private static ThreadLocal tl_tsdf = new ThreadLocal(); // setTimestamp() SimpleDateFormat
4646

4747
/**
4848
* Constructor for the PreparedStatement class.
@@ -64,6 +64,15 @@ public PreparedStatement(Connection connection, String sql) throws SQLException
6464

6565
this.sql = sql;
6666
this.connection = connection;
67+
68+
// might just as well create it here, so we don't take the hit later
69+
70+
SimpleDateFormat df = new SimpleDateFormat("''yyyy-MM-dd''");
71+
tl_df.set(df);
72+
73+
df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
74+
tl_tsdf.set(df);
75+
6776
for (i = 0; i < sql.length(); ++i)
6877
{
6978
int c = sql.charAt(i);
@@ -89,10 +98,11 @@ public PreparedStatement(Connection connection, String sql) throws SQLException
8998
/**
9099
* New in 7.1 - overides Statement.close() to dispose of a few local objects
91100
*/
92-
public void close() throws SQLException {
101+
public void close() throws SQLException
102+
{
93103
// free the ThreadLocal caches
94104
tl_df.set(null);
95-
105+
tl_tsdf.set(null);
96106
super.close();
97107
}
98108

@@ -333,10 +343,6 @@ public void setBytes(int parameterIndex, byte x[]) throws SQLException
333343
public void setDate(int parameterIndex, java.sql.Date x) throws SQLException
334344
{
335345
SimpleDateFormat df = (SimpleDateFormat) tl_df.get();
336-
if(df==null) {
337-
df = new SimpleDateFormat("''yyyy-MM-dd''");
338-
tl_df.set(df);
339-
}
340346

341347
set(parameterIndex, df.format(x));
342348

@@ -376,10 +382,6 @@ public void setTime(int parameterIndex, Time x) throws SQLException
376382
public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException
377383
{
378384
SimpleDateFormat df = (SimpleDateFormat) tl_tsdf.get();
379-
if(df==null) {
380-
df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
381-
tl_tsdf.set(df);
382-
}
383385
df.setTimeZone(TimeZone.getTimeZone("GMT"));
384386

385387
// Use the shared StringBuffer

0 commit comments

Comments
 (0)