0

当我的应用程序检测到特定错误时,我需要刷新 GlassFish 中的池。是否可以在 Java 应用程序内的 GlassFish 上执行命令?当出现错误时,我只需要刷新这个池。

4

1 回答 1

0

可以通过 SSH 完成

public class FlushPool {

    public static void flushConncetionPool(String nameConnectionPool){
        Session session = null;
        Channel channel = null;

        JSch jsch = new JSch();
        try {
            session = jsch.getSession("username", "host", port);
            java.util.Properties config = new java.util.Properties();
            config.put("StrictHostKeyChecking", "no");
            session.setConfig(config);
            session.setPassword("password");                
            session.connect();

            channel = session.openChannel("shell");


            OutputStream ops = channel.getOutputStream();
            PrintStream ps = new PrintStream(ops, true);
            channel.connect();


            ps.println("sudo su -");          
            ps.println("/app/glassfish/glassfish/bin/asadmin --user admin --passwordfile password.txt flush-connection-pool " + nameConnectionPool);
            session.diconect();
            channel.disconect();
        }catch(Exception e){
           // do something
        }


  }
}

password.txt 必须在服务器端

 AS_ADMIN_PASSWORD = senha
 AS_ADMIN_ADMIN_PASSWORD = senha
 AS_ADMIN_USERPASSWORD=senha 
 AS_ADMIN_MASTERPASSWORD= senha
于 2013-09-11T11:40:56.610 回答