feat: 添加主线程操作插件检测

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2016-07-05 11:01:13 +08:00
parent b3d6a2e6ba
commit ae621a855e

View File

@ -2,9 +2,10 @@ package pw.yumc.Yum.runnables;
import java.lang.Thread.State; import java.lang.Thread.State;
import java.util.TimerTask; import java.util.TimerTask;
import java.util.logging.Level;
import cn.citycraft.PluginHelper.kit.PKit; import org.bukkit.plugin.Plugin;
import cn.citycraft.PluginHelper.kit.PluginKit;
/** /**
* 线程安全检查任务 * 线程安全检查任务
@ -13,7 +14,11 @@ import cn.citycraft.PluginHelper.kit.PKit;
* @author * @author
*/ */
public class MainThreadCheckTask extends TimerTask { public class MainThreadCheckTask extends TimerTask {
public String prefix = "§6[§bYum §a线程管理§6] ";
public String warnPNet = "§6插件 §b%s §c在主线程进行网络操作 §4服务器处于停止状态...";
public String warnPIO = "§6插件 §b%s §c在主线程进行IO操作 §4服务器处于停止状态...";
public String warnNet = "§c主线程存在网络操作 §4服务器处于停止状态...";
public String warnIO = "§c主线程存在IO操作 §4服务器处于停止状态...";
private final Thread mainThread; private final Thread mainThread;
public MainThreadCheckTask(final Thread mainThread) { public MainThreadCheckTask(final Thread mainThread) {
@ -37,12 +42,22 @@ public class MainThreadCheckTask extends TimerTask {
if (isElementEqual(topElement, "java.net.DualStackPlainSocketImpl", "connect0") if (isElementEqual(topElement, "java.net.DualStackPlainSocketImpl", "connect0")
|| isElementEqual(topElement, "java.net.SocketInputStream", "socketRead0") || isElementEqual(topElement, "java.net.SocketInputStream", "socketRead0")
|| isElementEqual(topElement, "java.net.SocketOutputStream", "socketWrite0")) { || isElementEqual(topElement, "java.net.SocketOutputStream", "socketWrite0")) {
PKit.i().getLogger().log(Level.WARNING, "主线程存在网络操作 服务器处于停止状态...", stackTrace); final Plugin plugin = PluginKit.getOperatePlugin(stackTrace);
if (plugin != null) {
PluginKit.sc(String.format(prefix + warnPNet, plugin.getName()));
} else {
PluginKit.sc(prefix + warnNet);
}
} }
// File (in) - java.io.FileInputStream.readBytes // File (in) - java.io.FileInputStream.readBytes
// File (out) - java.io.FileOutputStream.writeBytes // File (out) - java.io.FileOutputStream.writeBytes
else if (isElementEqual(topElement, "java.io.FileInputStream", "readBytes") || isElementEqual(topElement, "java.io.FileOutputStream", "writeBytes")) { else if (isElementEqual(topElement, "java.io.FileInputStream", "readBytes") || isElementEqual(topElement, "java.io.FileOutputStream", "writeBytes")) {
PKit.i().getLogger().log(Level.WARNING, "主线程存在IO操作 服务器处于停止状态...", stackTrace); final Plugin plugin = PluginKit.getOperatePlugin(stackTrace);
if (plugin != null) {
PluginKit.sc(String.format(prefix + warnPIO, plugin.getName()));
} else {
PluginKit.sc(prefix + warnIO);
}
} }
} }
} }