标签:java spring-mvc jar processbuilder
我有一个可运行的JAR文件,计划使用Timer独立运行.
通过Web应用程序(在Spring MVC中开发)执行相同的JAR.
我必须限制JAR的执行,如果jar正在通过计时器执行,那么那时它不允许通过Web应用程序执行.
注意:[我使用了processbuilder来执行JAR.]
解决方法:
我认为你正在开发可授权的jar.
在我的拙见中,对于这种罐子,最好嵌入数据库并在Db中保存执行时间和端口使用,并比较使用时间并限制它.由于系统时间差异或防病毒res或系统时间分配res等原因,计时器方法不安全.但是对于监视器Web,您可以通过WatchDog应用程序来处理此类问题,
public class Watchdog implements Runnable {
private Vector observers = new Vector(1);
private long timeout = -1;
private volatile boolean stopped = false;
public static final String ERROR_INVALID_TIMEOUT = "timeout less than 1.";
/**
* Constructor for Watchdog.
* @param timeout the timeout to use in milliseconds (must be >= 1).
*/
public Watchdog(long timeout) {
if (timeout < 1) {
throw new IllegalArgumentException(ERROR_INVALID_TIMEOUT);
}
this.timeout = timeout;
}
public void addTimeoutObserver(TimeoutObserver to) {
observers.addElement(to);
}
public void removeTimeoutObserver(TimeoutObserver to) {
//no need to synchronize, as Vector is always synchronized
observers.removeElement(to);
}
protected final void fireTimeoutOccured() {
Enumeration e = observers.elements();
while (e.hasMoreElements()) {
((TimeoutObserver) e.nextElement()).timeoutOccured(this);
}
}
/**
* Start the watch dog.
*/
public synchronized void start() {
stopped = false;
Thread t = new Thread(this, "WATCHDOG");
t.setDaemon(true);
t.start();
}
/**
* Stop the watch dog.
*/
public synchronized void stop() {
stopped = true;
notifyAll();
}
public synchronized void run() {
final long until = System.currentTimeMillis() + timeout;
long now;
while (!stopped && until > (now = System.currentTimeMillis())) {
try {
wait(until - now);
Boolean SafeToContinue=CheckDbCountDay();
if(SafeToContinue)
ExecJarUsingStrategyPattern(new StrategyDoIt());
else ExecJarUsingStrategyPattern(new showMessage());
} catch (InterruptedException e) {
callBack("plz call support");
}
}
if (!stopped) {
fireTimeoutOccured();
}
}
}
标签:java,spring-mvc,jar,processbuilder 来源: https://codeday.me/bug/20190608/1198538.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。