📄 autohtmlgenerater.java
字号:
package com.easyjf.news.business;
import java.util.Date;
import java.util.List;
public class AutoHtmlGenerater implements Runnable {
private static AutoHtmlGenerater generater=new AutoHtmlGenerater();
private Date beginTime;//开始运行时间
private int times=0;//循环运行次数
private int errNum=0;
private String siteRootPath;
private boolean pause=false;
private boolean stop=false;
private boolean running=false;;
private Thread thread;
public static AutoHtmlGenerater getInstance()
{
return generater;
}
public void run() {
thread=Thread.currentThread();
beginTime=new Date();
// TODO Auto-generated method stub
while(!stop)
{
running=true;
try{
Thread.sleep(1000);
generater();
times++;
}
catch(Exception e)
{
e.printStackTrace();
}
}
thread=null;
running=false;
}
public void start()
{
//弟一次运行
if(thread==null)
{
stop=false;
thread=new Thread(this);
thread.start();
}
else if(pause)//暂停后重新运行
{
pause=false;
if(thread.isInterrupted())thread.start();
System.out.println("开始运行...");
}
}
public void pause()
{
pause=true;
if(thread!=null && thread.isAlive())thread.interrupt();
running=false;
stop=true;
System.out.println("暂停运行...");
}
public void stop()
{
stop=true;
}
public void generater()
{
List list=DynamicStaticPair.query("types=1");
if(list!=null)
{
for(int i=0;i<list.size();i++){
DynamicStaticPair dp=(DynamicStaticPair)list.get(i);
dp.changeSiteRootpath(siteRootPath);
try
{
//计算时间,若达到转换条件则进行转换
if(dp.getIntervals()!=null && (dp.getIntervals().intValue()>0)){
Date d=new Date();
if(dp.getVdate()==null || ((d.getTime()-dp.getVdate().getTime())>(dp.getIntervals().intValue()*1000)))
dp.generater();
}
Thread.sleep(1500);
}
catch(Exception e)
{
errNum++;
e.printStackTrace();
}
}
}
}
public Date getBeginTime() {
return beginTime;
}
public void setBeginTime(Date beginTime) {
this.beginTime = beginTime;
}
public String getSiteRootPath() {
return siteRootPath;
}
public void setSiteRootPath(String siteRootPath) {
this.siteRootPath = siteRootPath;
}
public int getTimes() {
return times;
}
public int getErrNum() {
return errNum;
}
public boolean isPause() {
return pause;
}
public boolean isStop() {
return stop;
}
public boolean isRunning() {
return running;
}
public String showStatus()
{
String ret="示启动";
if(pause)
{
ret="暂停";
}
else if(running)
{
ret="运行中";
}
return ret;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -