JBOSS 定期停止服务,启动服务脚本解决办法
发布时间:2010-06-14 17:12:30 文章来源:www.iduyao.cn 采编人员:星星草
JBOSS 定期停止服务,启动服务脚本
项目使用 jboss 5.0.1 GA版本,最近总是出现系统 cpu 400%,内存耗尽的问题,查看jboss日志也没有发现什么问题。
无奈之举,想写一个脚本,每周日的晚上 23 点重启jboss服务,可是写了半天,在windows下都没有成功,请大家查看下,谢谢!
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.util.Date;
import java.io.File;
import java.text.SimpleDateFormat;
import java.io.FileOutputStream;
import java.io.RandomAccessFile;
public class RestartjbossService {
private static String separator = File.separator;
private static String filePath = "d:"+separator+"";
public static void main(String[] args) throws InterruptedException {
String cmd1 = "cmd.exe ";// "sh ";//
String cmd2 = "c: ";// "-c ";//
//JBOSS 位置
String cmd31 = "C:"+separator+"jboss-5.0.0.CR2"+separator+"bin"+separator+"shutdown.bat -S";// "/home/posapp/jboss-5.1.0.GA/bin/shutdown.sh -S ";//
String cmd33 = "C:"+separator+"jboss-5.0.0.CR2"+separator+"bin"+separator+"run.bat -b 0.0.0.0 & ";
boolean isRestart = false;
Date date = new Date();
int hours = date.getHours();
if (hours == 14) {
isRestart = true;
}
SimpleDateFormat sim=new SimpleDateFormat("yyyy-MM-dd HH:ss:mm");
while (isRestart) {
try {
String[] cmd = new String[3];
Date start = new Date();
println(sim.format(start) + ":停止服务...........");
cmd[0] = cmd1;
cmd[1] = cmd2;
cmd[2] = cmd31;
Runtime rt = Runtime.getRuntime();
println("Execing " + cmd[0] + "" + cmd[1] + "" + cmd[2]);
Process proc = rt.exec(cmd);
StreamGobbler errorGobbler = new StreamGobbler(proc.getInputStream(), "ERROR");
StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream(), "OUTPUT");
errorGobbler.start();
outputGobbler.start();
Thread.sleep(1000);
println("启动服务....... ");
cmd[0] = cmd1;
cmd[1] = cmd2;
cmd[2] = cmd33;
rt = Runtime.getRuntime();
println("Execing " + cmd[0] + "=" + cmd[1] + "=" + cmd[2]);
proc = rt.exec(cmd);
StreamGobbler e = new StreamGobbler(proc.getInputStream(), "ERROR");
StreamGobbler o = new StreamGobbler(proc.getInputStream(), "OUTPUT");
e.start();
o.start();
Date end = new Date();
println(sim.format(end) + ":服务启动完成........... ");
isRestart = false;
} catch (Exception e) {
println(e.getMessage());
}
}
}
static class StreamGobbler extends Thread {
InputStream is;
String type;
StreamGobbler(InputStream is, String type) {
this.is = is;
this.type = type;
}
public void run() {
try {
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line = null;
while ((line = br.readLine()) != null)
RestartjbossService.println(type + "> " + line);
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
//写日志
static void println(String fileContent) {
String fileName = "restartJBoss"+ new SimpleDateFormat("yyyy-MM-dd").format(new Date(System.currentTimeMillis())) + ".log";
File path = new File(filePath);
if (!path.exists()) {
path.mkdir();
}
File file = new File(path, fileName);
// 如果文件长度大于10M,则改名成备份文件进行存储。
if (file.length() > 10 * 1024 * 1024) {
String rename = fileName+ new SimpleDateFormat("yyyyMMddHHmmss").format(new Date(System.currentTimeMillis()));
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。
其他相似内容:
-
jboss不能部署项目
我的jboss可以正常启动,但是部署项目时报出大量错误... 请高手帮忙解决下这是怎么回事... 感激不尽 我的j...
-
错误: javax.naming.NameNotFoundException: StatfulEjbBean not bound
刚学Jboos用的是Myeclipse,刚写第一个程序就不会了。运行...
-
jboss出错了,求解。在线等。
操作系统,solaris10 x86 ,启动jboss报错。日志如下。
求解,在线等。
# sh /export/home/jboss/jboss-...
-
JBOSS Incomplete Deployment listing 问题?
运行JBOSS出下列信息:
16:44:01,953 ERROR [URLDeploymentScanner] Incomplete Deplo...
-
JBOSS 5 简单的EJB3.0 热布署没有问题 如里先布署再启动就 NullPointerException
JBOSS 5 简单的EJB3.0 热布署没有问题
但是...
-
Jboss6.0.0 final版能否进行目录布署
请教一下,Jboss6.0.0 final版能否进行目录布署,我用eclipse + jboss进行开发时,每次修改页面或...
-
规则引擎与工作流的区别在于?
小弟想请教一下各位达人,规则引擎与工作流的区别在于什么地方?权限?角色?还是其它什么地方?
还有一些问题...
-
更新Jboss_Root\server\default\MyApp.war下的文件,项目重新启动后,效果和没改前一样。
需求:
1,MyApp.war(文件夹名)项目放到Jbo...
-
jboss发布项目出错
删除项目JBOSS能正常启动
11:42:06,968 ERROR [AbstractKernelController] Error installing to Parse: name...
-
jboss + eclipse 如何设置才能不重启服务就能自动编译jsp
jboss + eclipse 如何设置才能不重启服务就能自动编译jsp
现有我每次...