+12
@@ -0,0 +1,12 @@
|
||||
package com.baeldung.heap;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class HeapSizeDemoApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(HeapSizeDemoApplication.class, args);
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package com.baeldung.heap;
|
||||
|
||||
public class MemoryStats {
|
||||
private long heapSize;
|
||||
private long heapMaxSize;
|
||||
private long heapFreeSize;
|
||||
|
||||
public long getHeapSize() {
|
||||
return heapSize;
|
||||
}
|
||||
|
||||
public void setHeapSize(long heapSize) {
|
||||
this.heapSize = heapSize;
|
||||
}
|
||||
|
||||
public long getHeapMaxSize() {
|
||||
return heapMaxSize;
|
||||
}
|
||||
|
||||
public void setHeapMaxSize(long heapMaxSize) {
|
||||
this.heapMaxSize = heapMaxSize;
|
||||
}
|
||||
|
||||
public long getHeapFreeSize() {
|
||||
return heapFreeSize;
|
||||
}
|
||||
|
||||
public void setHeapFreeSize(long heapFreeSize) {
|
||||
this.heapFreeSize = heapFreeSize;
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package com.baeldung.heap;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class MemoryStatusController {
|
||||
|
||||
@GetMapping("memory-status")
|
||||
public MemoryStats getMemoryStatistics() {
|
||||
MemoryStats stats = new MemoryStats();
|
||||
stats.setHeapSize(Runtime.getRuntime()
|
||||
.totalMemory());
|
||||
stats.setHeapMaxSize(Runtime.getRuntime()
|
||||
.maxMemory());
|
||||
stats.setHeapFreeSize(Runtime.getRuntime()
|
||||
.freeMemory());
|
||||
return stats;
|
||||
}
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
JAVA_OPTS="-Xms512m -Xmx1024m"
|
||||
Reference in New Issue
Block a user