This is an automated email from the ASF dual-hosted git repository.
fschumacher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git
The following commit(s) were added to refs/heads/master by this push:
new 9362e18340 Replace java.util.Date with java.time based objects
9362e18340 is described below
commit 9362e183409f7e8ff51e7b16ec8c9c081ea3e656
Author: Felix Schumacher <[email protected]>
AuthorDate: Tue Apr 12 20:51:18 2022 +0200
Replace java.util.Date with java.time based objects
Part of #708
---
.../src/main/java/org/apache/jorphan/util/HeapDumper.java | 10 +++++-----
.../main/java/org/apache/jorphan/util/ThreadDumper.java | 10 +++++-----
.../src/main/java/org/apache/jmeter/NewDriver.java | 14 +++++++-------
3 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/src/jorphan/src/main/java/org/apache/jorphan/util/HeapDumper.java
b/src/jorphan/src/main/java/org/apache/jorphan/util/HeapDumper.java
index fffaf7c9b5..eef6b52e46 100644
--- a/src/jorphan/src/main/java/org/apache/jorphan/util/HeapDumper.java
+++ b/src/jorphan/src/main/java/org/apache/jorphan/util/HeapDumper.java
@@ -19,8 +19,9 @@ package org.apache.jorphan.util;
import java.io.File;
import java.lang.management.ManagementFactory;
-import java.text.SimpleDateFormat;
-import java.util.Date;
+import java.time.Instant;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
import javax.management.InstanceNotFoundException;
import javax.management.MBeanException;
@@ -159,10 +160,9 @@ public class HeapDumper {
* @return the name of the dump file that was created
* @throws Exception if the MXBean cannot be found, or if there is a
problem during invocation
*/
- @SuppressWarnings("JavaUtilDate")
public static String dumpHeap(File basedir, boolean live) throws Exception
{
- SimpleDateFormat timestampFormat = new
SimpleDateFormat("yyyyMMdd_hhmmss_SSS");
- String stamp = timestampFormat.format(new Date());
+ DateTimeFormatter timestampFormat =
DateTimeFormatter.ofPattern("yyyyMMdd_hhmmss_SSS").withZone(ZoneId.systemDefault());
+ String stamp = timestampFormat.format(Instant.now());
File temp = new File(basedir,"dump_"+stamp+".hprof");
final String path = temp.getPath();
dumpHeap(path, live);
diff --git
a/src/jorphan/src/main/java/org/apache/jorphan/util/ThreadDumper.java
b/src/jorphan/src/main/java/org/apache/jorphan/util/ThreadDumper.java
index 3f572a22e3..d97cb65870 100644
--- a/src/jorphan/src/main/java/org/apache/jorphan/util/ThreadDumper.java
+++ b/src/jorphan/src/main/java/org/apache/jorphan/util/ThreadDumper.java
@@ -27,8 +27,9 @@ import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;
import java.nio.charset.StandardCharsets;
-import java.text.SimpleDateFormat;
-import java.util.Date;
+import java.time.Instant;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
/**
* Utility class to create a Thread Dump
@@ -56,10 +57,9 @@ public class ThreadDumper {
* @return Name of file containing thread dump
* @throws Exception if file cannot we written
*/
- @SuppressWarnings("JavaUtilDate")
public static String threadDump(File basedir) throws Exception {
- SimpleDateFormat timestampFormat = new
SimpleDateFormat("yyyyMMdd_hhmmss_SSS");
- String stamp = timestampFormat.format(new Date());
+ DateTimeFormatter timestampFormat =
DateTimeFormatter.ofPattern("yyyyMMdd_hhmmss_SSS").withZone(ZoneId.systemDefault());
+ String stamp = timestampFormat.format(Instant.now());
File temp = new File(basedir,"thread_dump_"+stamp+".log");
final String path = temp.getPath();
try (FileOutputStream fos = new FileOutputStream(temp);
diff --git a/src/launcher/src/main/java/org/apache/jmeter/NewDriver.java
b/src/launcher/src/main/java/org/apache/jmeter/NewDriver.java
index 91d609c5f7..95a5350154 100644
--- a/src/launcher/src/main/java/org/apache/jmeter/NewDriver.java
+++ b/src/launcher/src/main/java/org/apache/jmeter/NewDriver.java
@@ -18,6 +18,7 @@
package org.apache.jmeter;
// N.B. this must only use standard Java packages
+
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
@@ -25,10 +26,11 @@ import java.io.StringWriter;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
-import java.text.SimpleDateFormat;
+import java.time.Instant;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Date;
import java.util.List;
import java.util.StringTokenizer;
@@ -344,19 +346,17 @@ public final class NewDriver {
/*
* If the fileName contains at least one set of paired single-quotes,
reformat using DateFormat
*/
- @SuppressWarnings("JavaUtilDate")
private static String replaceDateFormatInFileName(String fileName) {
try {
StringBuilder builder = new StringBuilder();
- // TODO: replace with java.time.*
- final Date date = new Date();
+ final Instant date = Instant.now();
int fromIndex = 0;
int begin = fileName.indexOf('\'', fromIndex);// $NON-NLS-1$
int end;
String format;
- SimpleDateFormat dateFormat;
+ DateTimeFormatter dateFormat;
while (begin != -1) {
builder.append(fileName.substring(fromIndex, begin));
@@ -368,7 +368,7 @@ public final class NewDriver {
}
format = fileName.substring(begin + 1, end);
- dateFormat = new SimpleDateFormat(format);
+ dateFormat =
DateTimeFormatter.ofPattern(format).withZone(ZoneId.systemDefault());
builder.append(dateFormat.format(date));
fromIndex = end + 1;