我正在开发一个需要展示网络和桌面应用程序的项目。 Web应用程序从我的客户端接收任务并存储它们(在数据库中)。桌面应用程序从数据库中获取任务并逐个执行。在我的Web应用程序中,我正在使用java servlet,Web服务......
有时我的glassfish服务器(v 3.1.2)会冻结或被阻塞,需要重新启动才能继续正常工作。我可以通过监视他并发现他冻结的时间来检测这种错误(通过调用抛出异常的简单Web服务方法,也会抛出异常的简单http请求等)。
我希望我的桌面应用程序获得Glassfish服务器状态,如果
是否有人遇到此问题并且有任何解决方案。我厌倦了手动重启glassfish服务器。
答案 0 :(得分:3)
我在生产中运行Glassfish 3.1.2几个月没有问题。我怀疑您所看到的冻结是您部署到它的应用程序的问题。
我认为你最好花时间调查和纠正悬而未决的问题。当发生这种情况时,您是否尝试过使用Glassfish java进程的线程转储?
答案 1 :(得分:0)
我找到了自己想要分享的解决方案。
当我检测到Glassfish服务器出现问题时,我重启它。此解决方案仅适用于Linux(如果我找到Windows用户的simular,我将编辑此答案)。您也可能需要在root用户下的“/ etc / sudoers”中为您的用户添加此行,adrian是我的用户名。
adrian ALL=(ALL:ALL) ALL
GlassFish类:( U需要更改glassfishPath和domainName)
package es.web.glassfish;
import es.os.linux.Konsole;
import java.io.IOException;
/**
*
* @author adrian
*/
public class Glassfish {
private final static String glassfishPath = "/home/adrian/glassfish-4.0/";
private final static String domainName = "domain1";
public static String startGlassfishServer() throws IOException, InterruptedException {
String command = glassfishPath + "bin/asadmin start-domain "+domainName;
return Konsole.executeCommand(command);
}
public static String stopGlassfishServer() throws IOException, InterruptedException {
String command = glassfishPath + "bin/asadmin stop-domain "+domainName;
return Konsole.executeCommand(command);
}
public static String restrartGlassfishServer() throws IOException, InterruptedException {
String command = glassfishPath + "bin/asadmin restart-domain "+domainName;
return Konsole.executeCommand(command);
}
}
Konsole类:
package es.os.linux;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
*
* @author adrian
*/
public class Konsole {
static Process process;
static BufferedReader reader;
public static String executeCommand(String command) throws IOException, InterruptedException {
String rez = "";
process = Runtime.getRuntime().exec(command);
process.waitFor();
reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
rez += line + "#";
}
return rez;
}
}
测试类:
public class test {
/**
* @param args the command line arguments
*/
public static void main(String[] args){
try {
System.out.println("START");
System.out.println(Glassfish.startGlassfishServer());
System.out.println("RESTART");
System.out.println(Glassfish.restrartGlassfishServer());
System.out.println("STOP");
System.out.println(Glassfish.stopGlassfishServer());
} catch (IOException ex) {
ex.printStackTrace();
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
测试类输出:
START
Waiting for domain1 to start ............#Successfully started the domain : domain1#domain Location: /home/adrian/glassfish-4.0/glassfish/domains/domain1#Log File: /home/adrian/glassfish-4.0/glassfish/domains/domain1/logs/server.log#Admin Port: 4848#Command start-domain executed successfully.#
RESTART
Successfully restarted the domain#Command restart-domain executed successfully.#
STOP
Waiting for the domain to stop #Command stop-domain executed successfully.#