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

Commitdb491a6

Browse files
committed
SimpleDateFormat performance improvement, thread-safe.
Barry Lind
1 parent3938150 commitdb491a6

File tree

1 file changed

+8
-19
lines changed

1 file changed

+8
-19
lines changed

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

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,6 @@ public PreparedStatement(Connection connection, String sql) throws SQLException
6565
this.sql =sql;
6666
this.connection =connection;
6767

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-
7668
for (i =0;i <sql.length(); ++i)
7769
{
7870
intc =sql.charAt(i);
@@ -95,17 +87,6 @@ public PreparedStatement(Connection connection, String sql) throws SQLException
9587
templateStrings[i] = (String)v.elementAt(i);
9688
}
9789

98-
/**
99-
* New in 7.1 - overides Statement.close() to dispose of a few local objects
100-
*/
101-
publicvoidclose()throwsSQLException
102-
{
103-
// free the ThreadLocal caches
104-
tl_df.set(null);
105-
tl_tsdf.set(null);
106-
super.close();
107-
}
108-
10990
/**
11091
* A Prepared SQL query is executed and its ResultSet is returned
11192
*
@@ -343,6 +324,10 @@ public void setBytes(int parameterIndex, byte x[]) throws SQLException
343324
publicvoidsetDate(intparameterIndex,java.sql.Datex)throwsSQLException
344325
{
345326
SimpleDateFormatdf = (SimpleDateFormat)tl_df.get();
327+
if(df==null) {
328+
df =newSimpleDateFormat("''yyyy-MM-dd''");
329+
tl_df.set(df);
330+
}
346331

347332
set(parameterIndex,df.format(x));
348333

@@ -382,6 +367,10 @@ public void setTime(int parameterIndex, Time x) throws SQLException
382367
publicvoidsetTimestamp(intparameterIndex,Timestampx)throwsSQLException
383368
{
384369
SimpleDateFormatdf = (SimpleDateFormat)tl_tsdf.get();
370+
if(df==null) {
371+
df =newSimpleDateFormat("yyyy-MM-dd HH:mm:ss");
372+
tl_tsdf.set(df);
373+
}
385374
df.setTimeZone(TimeZone.getTimeZone("GMT"));
386375

387376
// Use the shared StringBuffer

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp