Teamcenter AWC 全文检索 运行生成索引命令无效,处理方法1

方法:获取当前时间  执行索引命令 执行成功,写到properties文件中,下次执行,从上次执行的时间开始


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;

import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import cn.hutool.setting.dialect.Props;
import cn.hutool.core.io.resource.ResourceUtil;
import cn.hutool.core.util.StrUtil;


import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class RunSolrIndex {

public static String proPath="/teamcenter/Siemens/Teamcenter14/TcFTSIndexer/conf/TcFtsIndexer_objdata.properties";
public static int runClount=0;
public static Log log = LogFactory.get();
public static int divMinutes=5;
public static String command = "/teamcenter/Siemens/Teamcenter14/TcFTSIndexer/bin/runTcFTSIndexer.sh -task=objdata:index";
public static void main(String[] args) {
try {
cycle1();
} catch (Exception e) {
e.printStackTrace();
}
}

public static void cycle1() throws Exception {
final Timer timer = new Timer();
timer.schedule(new TimerTask() {
public void run() {
runClount++;
System.out.println("runClount: " + runClount);
try {
// 假设你的shell脚本路径是 /path/to/your/script.sh
Date startDate=new Date();
// 使用Runtime执行命令
Process process = Runtime.getRuntime().exec(command);
// 读取脚本输出
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
// 等待脚本执行完成
process.waitFor();
// 获取退出值
int exitValue = process.exitValue();
setTime(startDate);
System.out.println("Exit value: " + exitValue);
} catch (Exception e) {
e.printStackTrace();
log.error(e);
}
}
}, 0, 1000*divMinutes*60);//5分钟
}

public static void setTime(Date date) {
Properties props = new Properties();

try {
// 读取属性文件
props.load(new FileInputStream(proPath));

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");

String formattedDate = sdf.format(date);

props.setProperty("querytimesslicestep.startTime", formattedDate);

// 保存属性到文件
props.store(new FileOutputStream(proPath), null);

} catch (IOException ex) {
ex.printStackTrace();
log.error(ex);
}
}
}

posted @ 2024-09-19 23:00  张永全-PLM顾问  阅读(38)  评论(0编辑  收藏  举报