Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit54361b4

Browse files
committed
High memory usage
Here is a patch which inspired by Michael Stephens that should workDave Cramer
1 parent06f6404 commit54361b4

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-
privateThreadLocaltl_df =newThreadLocal();// setDate() SimpleDateFormat
45-
privateThreadLocaltl_tsdf =newThreadLocal();// setTimestamp() SimpleDateFormat
44+
privatestaticThreadLocaltl_df =newThreadLocal();// setDate() SimpleDateFormat
45+
privatestaticThreadLocaltl_tsdf =newThreadLocal();// 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+
SimpleDateFormatdf =newSimpleDateFormat("''yyyy-MM-dd''");
71+
tl_df.set(df);
72+
73+
df =newSimpleDateFormat("yyyy-MM-dd HH:mm:ss");
74+
tl_tsdf.set(df);
75+
6776
for (i =0;i <sql.length(); ++i)
6877
{
6978
intc =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-
publicvoidclose()throwsSQLException {
101+
publicvoidclose()throwsSQLException
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
publicvoidsetDate(intparameterIndex,java.sql.Datex)throwsSQLException
334344
{
335345
SimpleDateFormatdf = (SimpleDateFormat)tl_df.get();
336-
if(df==null) {
337-
df =newSimpleDateFormat("''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
publicvoidsetTimestamp(intparameterIndex,Timestampx)throwsSQLException
377383
{
378384
SimpleDateFormatdf = (SimpleDateFormat)tl_tsdf.get();
379-
if(df==null) {
380-
df =newSimpleDateFormat("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)

[8]ページ先頭

©2009-2025 Movatter.jp