You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2018/11/23 10:16:56 UTC

httpcomponents-core git commit: SimpleDateFormat is not thread safe; use HttpDateGenerator instead.

Repository: httpcomponents-core
Updated Branches:
  refs/heads/master f73883b6e -> 5f7473987


SimpleDateFormat is not thread safe; use HttpDateGenerator instead.


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/5f747398
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/5f747398
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/5f747398

Branch: refs/heads/master
Commit: 5f7473987c628a71e7fed3dc77d487e12b8d7df3
Parents: f73883b
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Fri Nov 23 11:13:49 2018 +0100
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Fri Nov 23 11:13:49 2018 +0100

----------------------------------------------------------------------
 .../hc/core5/http/examples/AsyncFileServerExample.java   | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/5f747398/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncFileServerExample.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncFileServerExample.java b/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncFileServerExample.java
index 3a95887..6bc7964 100644
--- a/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncFileServerExample.java
+++ b/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncFileServerExample.java
@@ -31,8 +31,6 @@ import java.io.IOException;
 import java.net.InetSocketAddress;
 import java.net.URI;
 import java.net.URISyntaxException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
 import java.util.Locale;
 import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
@@ -55,6 +53,7 @@ import org.apache.hc.core5.http.nio.entity.FileEntityProducer;
 import org.apache.hc.core5.http.nio.entity.NoopEntityConsumer;
 import org.apache.hc.core5.http.protocol.HttpContext;
 import org.apache.hc.core5.http.protocol.HttpCoreContext;
+import org.apache.hc.core5.http.protocol.HttpDateGenerator;
 import org.apache.hc.core5.io.CloseMode;
 import org.apache.hc.core5.reactor.IOReactorConfig;
 import org.apache.hc.core5.reactor.ListenerEndpoint;
@@ -65,8 +64,6 @@ import org.apache.hc.core5.util.TimeValue;
  */
 public class AsyncFileServerExample {
 
-    static final SimpleDateFormat DATE_FORMATTER = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS Z");
-
     /** Example command line args: {@code "c:\temp" 8080} */
     public static void main(final String[] args) throws Exception {
         if (args.length < 1) {
@@ -144,7 +141,11 @@ public class AsyncFileServerExample {
 
                             final HttpCoreContext coreContext = HttpCoreContext.adapt(context);
                             final EndpointDetails endpoint = coreContext.getEndpointDetails();
-                            System.out.println(DATE_FORMATTER.format(new Date()) + " | " + endpoint + " | serving file " + file.getPath());
+
+                            System.out.println(HttpDateGenerator.INSTANCE.getCurrentDate() +
+                                    " | " + endpoint +
+                                    " | serving file " + file.getPath());
+
                             responseTrigger.submitResponse(new BasicResponseProducer(
                                     HttpStatus.SC_OK, new FileEntityProducer(file, contentType)), context);
                         }