mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-05-03 03:43:54 +01:00
Improve diagnostics when temporary heap dump file can't be deleted
This commit is contained in:
+19
-2
@@ -24,12 +24,16 @@ import java.lang.management.PlatformManagedObject;
|
|||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.channels.ReadableByteChannel;
|
import java.nio.channels.ReadableByteChannel;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.locks.Lock;
|
import java.util.concurrent.locks.Lock;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.boot.endpoint.Endpoint;
|
import org.springframework.boot.endpoint.Endpoint;
|
||||||
import org.springframework.boot.endpoint.EndpointType;
|
import org.springframework.boot.endpoint.EndpointType;
|
||||||
@@ -184,6 +188,8 @@ public class HeapDumpWebEndpoint {
|
|||||||
|
|
||||||
private static final class TemporaryFileSystemResource extends FileSystemResource {
|
private static final class TemporaryFileSystemResource extends FileSystemResource {
|
||||||
|
|
||||||
|
private final Log logger = LogFactory.getLog(getClass());
|
||||||
|
|
||||||
private TemporaryFileSystemResource(File file) {
|
private TemporaryFileSystemResource(File file) {
|
||||||
super(file);
|
super(file);
|
||||||
}
|
}
|
||||||
@@ -204,7 +210,7 @@ public class HeapDumpWebEndpoint {
|
|||||||
readableChannel.close();
|
readableChannel.close();
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
getFile().delete();
|
deleteFile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -252,7 +258,7 @@ public class HeapDumpWebEndpoint {
|
|||||||
delegate.close();
|
delegate.close();
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
getFile().delete();
|
deleteFile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -274,6 +280,17 @@ public class HeapDumpWebEndpoint {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void deleteFile() {
|
||||||
|
try {
|
||||||
|
Files.delete(getFile().toPath());
|
||||||
|
}
|
||||||
|
catch (IOException ex) {
|
||||||
|
TemporaryFileSystemResource.this.logger.warn(
|
||||||
|
"Failed to delete temporary heap dump file '" + getFile() + "'",
|
||||||
|
ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isFile() {
|
public boolean isFile() {
|
||||||
// Prevent zero-copy so we can delete the file on close
|
// Prevent zero-copy so we can delete the file on close
|
||||||
|
|||||||
Reference in New Issue
Block a user