Skip to content
Permalink
Browse files
Replace java.util.Date with java.time based objects
Part of #708
  • Loading branch information
FSchumacher committed Apr 12, 2022
1 parent d9f775e commit 9362e183409f7e8ff51e7b16ec8c9c081ea3e656
Showing 3 changed files with 17 additions and 17 deletions.
@@ -19,8 +19,9 @@

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 static String dumpHeap(boolean live) throws Exception {
* @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);
@@ -27,8 +27,9 @@
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 static String threadDump() throws Exception {
* @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);
@@ -18,17 +18,19 @@
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;
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 @@ private static String getCommandLineArgument(String[] args, int id, String name)
/*
* 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 @@ private static String replaceDateFormatInFileName(String fileName) {
}

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;

0 comments on commit 9362e18

Please sign in to comment.