mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-04 23:47:59 +01:00
Run ThreadMXBean method in the enable
method
This commit is contained in:
parent
b370f55ee0
commit
ef5c15fb6a
@ -36,9 +36,6 @@ public final class BenchmarkManager {
|
|||||||
private static final List<String> THREADS = new ArrayList<>();
|
private static final List<String> THREADS = new ArrayList<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
THREAD_MX_BEAN.setThreadContentionMonitoringEnabled(true);
|
|
||||||
THREAD_MX_BEAN.setThreadCpuTimeEnabled(true);
|
|
||||||
|
|
||||||
THREADS.add(THREAD_NAME_BLOCK_BATCH);
|
THREADS.add(THREAD_NAME_BLOCK_BATCH);
|
||||||
THREADS.add(THREAD_NAME_SCHEDULER);
|
THREADS.add(THREAD_NAME_SCHEDULER);
|
||||||
THREADS.add(THREAD_NAME_TICK_SCHEDULER);
|
THREADS.add(THREAD_NAME_TICK_SCHEDULER);
|
||||||
@ -59,23 +56,21 @@ public final class BenchmarkManager {
|
|||||||
|
|
||||||
public void enable(@NotNull Duration duration) {
|
public void enable(@NotNull Duration duration) {
|
||||||
Check.stateCondition(enabled, "A benchmark is already running, please disable it first.");
|
Check.stateCondition(enabled, "A benchmark is already running, please disable it first.");
|
||||||
|
THREAD_MX_BEAN.setThreadContentionMonitoringEnabled(true);
|
||||||
|
THREAD_MX_BEAN.setThreadCpuTimeEnabled(true);
|
||||||
|
|
||||||
time = duration.toMillis();
|
this.time = duration.toMillis();
|
||||||
|
|
||||||
final Thread thread = new Thread(null, () -> {
|
final Thread thread = new Thread(null, () -> {
|
||||||
|
|
||||||
while (!stop) {
|
while (!stop) {
|
||||||
refreshData();
|
refreshData();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Thread.sleep(time);
|
Thread.sleep(time);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
MinecraftServer.getExceptionManager().handleException(e);
|
MinecraftServer.getExceptionManager().handleException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stop = false;
|
stop = false;
|
||||||
|
|
||||||
}, MinecraftServer.THREAD_NAME_BENCHMARK);
|
}, MinecraftServer.THREAD_NAME_BENCHMARK);
|
||||||
thread.setDaemon(true);
|
thread.setDaemon(true);
|
||||||
thread.start();
|
thread.start();
|
||||||
|
Loading…
Reference in New Issue
Block a user