Former-commit-id: da045a2656a19bcafad4e2b4df8e9f845635bcac
master
wangbing 5 years ago
parent 35a070acdd
commit c7bc4ed05f

@ -1,45 +1,81 @@
package ${basePackage}.config;
import ${basePackage}.action.GlobalController;
import ${basePackage}.frame.utils.LogUtil;
import ${basePackage}.frame.utils.ProcessUtil;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import org.springframework.scheduling.Trigger;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.scheduling.support.CronTrigger;
import org.springframework.stereotype.Component;
import ${basePackage}.frame.utils.LogUtil;
import javax.annotation.PostConstruct;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.concurrent.Executors;
import java.util.Map;
import java.util.concurrent.ScheduledFuture;
/**
* Task,Task
* :@Profile("dev") () @Profile("prod")()
* :@Profile("dev") () ()
*/
@Configuration
@EnableScheduling
@Component
@Profile("dev")
public class TaskConfig implements SchedulingConfigurer {
@Scheduled(cron="0/5 * * * * ? ")
public void task(){
// todo 自定实现的定时任务
SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
HashMap<String, String> data = new HashMap<>();
data.put("time", format.format(new Date()));
GlobalController.pushAll(data);
public class TaskConfig extends ThreadPoolTaskScheduler {
public TaskConfig() {
futureMap = new HashMap<>();
setPoolSize(4);
initialize();
}
@PostConstruct
public void ss() {
TaskConfig.this.addTask(1L, new Runnable() {
@Override
public void run() {
SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
LogUtil.d(format.format(new Date()));
}
}, new CronTrigger("0/3 * * * * ? "));
}
/**
* Spring Schedule 线
* 线 SchedulingConfigurerconfigureTasks
*
* @param scheduledTaskRegistrar
*/
@Override
public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
scheduledTaskRegistrar.setScheduler(Executors.newScheduledThreadPool(3));
private Map<String, ScheduledFuture<?>> futureMap;
public boolean addTask(Long taskId, Runnable runnable, Trigger trigger) {
ScheduledFuture<?> schedule = this.schedule(runnable, trigger);
futureMap.put(taskId.toString(), schedule);
System.out.println("DynamicTask.startCron()");
return true;
}
// public void configureTasks(ScheduledTaskRegistrar registrar) {
// // 开启新线程模拟外部更改了任务执行周期
// new Thread(new Runnable() {
// @Override
// public void run() {
// try {
// Thread.sleep(15 * 1000);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
//
// cron = "0/10 * * * * ? ";
// System.err.println("cron change to: " + cron);
// }
// }).start();
// this.registrar = registrar;
// this.registrar.setScheduler(Executors.newScheduledThreadPool(3));
// CronTrigger cronTrigger = new CronTrigger(cron) {
//// @Override
//// public Date nextExecutionTime(TriggerContext triggerContext) {
//// // 任务触发,可修改任务的执行周期
//// CronTrigger trigger = new CronTrigger(cron);
//// return trigger.nextExecutionTime(triggerContext);
//// }
// };
// }
}

@ -3,7 +3,7 @@
<div class="login-box">
<div class="login-title">系统登录</div>
<el-form :model="form" :rules="rules" ref="form" class="form">
<el-form :model="form" :rules="rules" ref="form" class="loginForm">
<el-form-item prop="username">
<el-input placeholder="用户名" v-model="form.username">
<template slot="prepend"><i class="icon iconfont el-icon-user"></i></template>
@ -68,14 +68,14 @@
color: #757575;
}
.form {
.loginForm {
width: 300px;
margin-top: 20px;
margin-left: 20px;
margin-right: 20px;
}
.form .el-input-group__prepend {
.loginForm .el-input-group__prepend {
padding: 10px;
}

Loading…
Cancel
Save

Powered by TurnKey Linux.