从java桌面应用程序启动、停止、重新启动Glassfish服务器
我正在开发一个项目,需要一个网络和桌面应用程序。web应用程序从我的客户端接收任务并将其存储(在数据库中)。桌面应用程序(从数据库)获取任务并逐个执行。在我的web应用程序中,我使用java servlet、web服务 有时,我的glassfish服务器(V3.1.2)冻结,或者他被阻塞,需要重新启动,以便他可以继续正常工作。我可以通过监视他来检测这种错误,并找出他何时冻结(通过调用引发异常的简单web服务方法、也引发异常的简单http请求等) 我希望我的桌面应用程序获得Glassfish服务器状态,如果从java桌面应用程序启动、停止、重新启动Glassfish服务器,java,glassfish,Java,Glassfish,我正在开发一个项目,需要一个网络和桌面应用程序。web应用程序从我的客户端接收任务并将其存储(在数据库中)。桌面应用程序(从数据库)获取任务并逐个执行。在我的web应用程序中,我使用java servlet、web服务 有时,我的glassfish服务器(V3.1.2)冻结,或者他被阻塞,需要重新启动,以便他可以继续正常工作。我可以通过监视他来检测这种错误,并找出他何时冻结(通过调用引发异常的简单web服务方法、也引发异常的简单http请求等) 我希望我的桌面应用程序获得Glassfish服务器
有没有人遇到过这个问题,并且有什么解决办法。我厌倦了手动重新启动glassfish服务器。我在生产环境中运行glassfish 3.1.2,一次运行几个月都没有问题。我怀疑您看到的冻结是您部署到其中的应用程序的问题
我认为你最好花点时间调查和解决悬而未决的问题。发生这种情况时,您是否尝试过对Glassfish java进程进行线程转储 我在生产中运行Glassfish 3.1.2,一次运行几个月,没有问题。我怀疑您看到的冻结是您部署到其中的应用程序的问题
我认为你最好花点时间调查和解决悬而未决的问题。发生这种情况时,您是否尝试过对Glassfish java进程进行线程转储 我找到了自己想要分享的解决方案 当我检测到Glassfish服务器出现问题时,我会重新启动它。此解决方案仅适用于Linux(如果我找到simular for windows用户,我将编辑此答案)。此外,您可能需要在根用户下的“/etc/sudoers”中为您的用户添加这一行,adrian是我的用户名
adrian ALL=(ALL:ALL) ALL
GlassFish类:(您需要更改glassfishPath和域名)
康索尔级:
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.#
我找到了自己想要分享的解决方案 当我检测到Glassfish服务器出现问题时,我会重新启动它。此解决方案仅适用于Linux(如果我找到simular for windows用户,我将编辑此答案)。此外,您可能需要在根用户下的“/etc/sudoers”中为您的用户添加这一行,adrian是我的用户名
adrian ALL=(ALL:ALL) ALL
GlassFish类:(您需要更改glassfishPath和域名)
康索尔级:
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.#
问题是我不能调用webservice方法,或者http客户端没有接收任何数据。尝试了很多方法,但只有重新启动有效。这表明应用程序正在耗尽HTTP线程池。同样,当你遇到这种情况时,你应该进行线程转储,这样你就可以看到发生了什么。我增加了http线程池,从那时起我就没有任何问题,但是如果有时发生,我想在发现问题后重新启动服务器。问题可能是我无法调用webservice方法,或者http客户端没有收到任何数据。尝试了很多方法,但只有重新启动有效。这表明应用程序正在耗尽HTTP线程池。同样,当你遇到这种情况时,你应该进行线程转储,这样你就可以看到发生了什么。我增加了http线程池,从那以后我就没有问题了,但是如果有时出现问题,我希望在发现问题后重新启动服务器。再次查看我上面的评论。此外,您没有正确使用Process/Runtime exec API。您正在执行进程的同一线程中读取输入流。这是一种让线程死锁在看似随机的执行中发生的好方法。我知道你的答案很有用,但并没有解决我的问题。此解决方案还可以在停止时从桌面应用程序启动glassfish服务器。Restart命令在服务器关闭时启动服务器,并在服务器启动时重新启动服务器。再次查看上面的注释。此外,您没有正确使用Process/Runtime exec API。您正在执行进程的同一线程中读取输入流。这是一种让线程死锁在看似随机的执行中发生的好方法。我知道你的答案很有用,但并没有解决我的问题。此解决方案还可以在停止时从桌面应用程序启动glassfish服务器。Restart命令在服务器关闭时启动服务器,并在服务器启动时重新启动服务器。