use of com.dtp.core.thread.DtpExecutor in project dynamic-tp by dromara.
the class TestController method task.
public void task() throws InterruptedException {
DtpExecutor dtpExecutor2 = DtpRegistry.getDtpExecutor("dtpExecutor2");
for (int i = 0; i < 100; i++) {
Thread.sleep(100);
dtpExecutor1.execute(() -> {
log.info("i am dynamic-tp-test-1 task");
});
dtpExecutor2.execute(() -> {
log.info("i am dynamic-tp-test-2 task");
});
}
}
use of com.dtp.core.thread.DtpExecutor in project dynamic-tp by dromara.
the class NotifyHelper method getNotifyItem.
public static NotifyItem getNotifyItem(DtpExecutor dtpExecutor, NotifyTypeEnum typeEnum) {
List<NotifyItem> notifyItems = dtpExecutor.getNotifyItems();
val notifyItemOpt = notifyItems.stream().filter(x -> typeEnum.getValue().equalsIgnoreCase(x.getType()) && x.isEnabled()).findFirst();
if (!notifyItemOpt.isPresent()) {
log.debug("DynamicTp notify, no such [{}] notify item configured, threadPoolName: {}", typeEnum.getValue(), dtpExecutor.getThreadPoolName());
return null;
}
return notifyItemOpt.get();
}
use of com.dtp.core.thread.DtpExecutor in project dynamic-tp by dromara.
the class AbstractNotifier method buildNoticeContent.
public String buildNoticeContent(NotifyPlatform platform, String template, DtpMainProp oldProp, List<String> diffs) {
String threadPoolName = oldProp.getDtpName();
DtpExecutor dtpExecutor = DtpRegistry.getDtpExecutor(threadPoolName);
String receivesStr = getReceives(platform.getPlatform(), platform.getReceivers());
String content = String.format(template, getInstance().getServiceName(), getInstance().getIp() + ":" + getInstance().getPort(), getInstance().getEnv(), populatePoolName(dtpExecutor), oldProp.getCorePoolSize(), dtpExecutor.getCorePoolSize(), oldProp.getMaxPoolSize(), dtpExecutor.getMaximumPoolSize(), oldProp.isAllowCoreThreadTimeOut(), dtpExecutor.allowsCoreThreadTimeOut(), oldProp.getKeepAliveTime(), dtpExecutor.getKeepAliveTime(TimeUnit.SECONDS), dtpExecutor.getQueueName(), oldProp.getQueueCapacity(), dtpExecutor.getQueueCapacity(), oldProp.getRejectType(), dtpExecutor.getRejectHandlerName(), receivesStr, DateTime.now());
return highlightNotifyContent(content, diffs);
}
use of com.dtp.core.thread.DtpExecutor in project dynamic-tp by dromara.
the class DtpMonitor method run.
private void run() {
List<String> dtpNames = DtpRegistry.listAllDtpNames();
List<String> commonNames = DtpRegistry.listAllCommonNames();
if (CollUtil.isEmpty(dtpNames) && CollUtil.isEmpty(commonNames)) {
return;
}
boolean enabledCollect = dtpProperties.isEnabledCollect();
dtpNames.forEach(x -> {
DtpExecutor executor = DtpRegistry.getDtpExecutor(x);
AlarmManager.triggerAlarm(() -> doAlarm(executor, ALARM_TYPES));
if (enabledCollect) {
ThreadPoolStats poolStats = MetricsConverter.convert(executor);
doCollect(poolStats);
}
});
if (!enabledCollect) {
return;
}
commonNames.forEach(x -> {
ExecutorWrapper wrapper = DtpRegistry.getCommonExecutor(x);
ThreadPoolStats poolStats = MetricsConverter.convert(wrapper);
doCollect(poolStats);
});
publishEvent();
}
use of com.dtp.core.thread.DtpExecutor in project dynamic-tp by dromara.
the class DtpEndpoint method invoke.
@ReadOperation
public List<Metrics> invoke() {
List<String> dtpNames = DtpRegistry.listAllDtpNames();
List<String> commonNames = DtpRegistry.listAllCommonNames();
List<Metrics> metricsList = Lists.newArrayList();
dtpNames.forEach(x -> {
DtpExecutor executor = DtpRegistry.getDtpExecutor(x);
metricsList.add(MetricsConverter.convert(executor));
});
commonNames.forEach(x -> {
ExecutorWrapper wrapper = DtpRegistry.getCommonExecutor(x);
metricsList.add(MetricsConverter.convert(wrapper));
});
JvmStats jvmStats = new JvmStats();
RuntimeInfo runtimeInfo = new RuntimeInfo();
jvmStats.setMaxMemory(FileUtil.readableFileSize(runtimeInfo.getMaxMemory()));
jvmStats.setTotalMemory(FileUtil.readableFileSize(runtimeInfo.getTotalMemory()));
jvmStats.setFreeMemory(FileUtil.readableFileSize(runtimeInfo.getFreeMemory()));
jvmStats.setUsableMemory(FileUtil.readableFileSize(runtimeInfo.getUsableMemory()));
metricsList.add(jvmStats);
return metricsList;
}
Aggregations