Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java XML-RPC异常从execute切换到executeAsync_Java_Apache_Asynchronous_Xml Rpc - Fatal编程技术网

Java XML-RPC异常从execute切换到executeAsync

Java XML-RPC异常从execute切换到executeAsync,java,apache,asynchronous,xml-rpc,Java,Apache,Asynchronous,Xml Rpc,下面的XML-RPC实现正在运行,我从中复制并稍微修改了它 与客户: public class DemoClient { public static void main (String[] args) { try { XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl(); config.setServerURL(new URL("http://127.0.0.1:8080/xmlrpc

下面的XML-RPC实现正在运行,我从中复制并稍微修改了它

与客户:

public class DemoClient {
  public static void main (String[] args) {
    try {
        XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
        config.setServerURL(new URL("http://127.0.0.1:8080/xmlrpc"));
        config.setEnabledForExtensions(true);  
        config.setConnectionTimeout(60 * 1000);
        config.setReplyTimeout(60 * 1000);

        XmlRpcClient client = new XmlRpcClient();

        // set configuration
        client.setConfig(config);

        // make the a regular call
        Object[] params = new Object[] { new Integer(2), new Integer(3) };

                    //!CRITICAL LINE!
        Integer result = (Integer) client.execute("sample.sum", params);

        System.out.println("2 + 3 = " + result);
    } catch (Exception e) {
        e.printStackTrace();
    }
  }
}
我先运行DemoServer,然后运行DemoClient,它会打印“2+3=5”。 但是如果我改变

Integer result = (Integer) client.execute("sample.sum", params);

然后我得到以下结果:

In error
java.lang.ExceptionInInitializerError
    at java.lang.Runtime.addShutdownHook(Runtime.java:192)
at java.util.logging.LogManager.<init>(LogManager.java:237)
at java.util.logging.LogManager$1.run(LogManager.java:177)
at java.security.AccessController.doPrivileged(Native Method)
at java.util.logging.LogManager.<clinit>(LogManager.java:158)
at java.util.logging.Logger.getLogger(Logger.java:273)
at sun.net.www.protocol.http.HttpURLConnection.<clinit>(HttpURLConnection.java:62)
at sun.net.www.protocol.http.Handler.openConnection(Handler.java:44)
at sun.net.www.protocol.http.Handler.openConnection(Handler.java:39)
at java.net.URL.openConnection(URL.java:945)
at org.apache.xmlrpc.client.XmlRpcSun15HttpTransport.newURLConnection(XmlRpcSun15HttpTransport.java:62)
at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.sendRequest(XmlRpcSunHttpTransport.java:62)
at org.apache.xmlrpc.client.XmlRpcClientWorker$1.run(XmlRpcClientWorker.java:80)
at java.lang.Thread.run(Thread.java:680)
Caused by: java.lang.IllegalStateException: Shutdown in progress
at java.lang.Shutdown.add(Shutdown.java:62)
at java.lang.ApplicationShutdownHooks.<clinit>(ApplicationShutdownHooks.java:21)
... 14 more

这里出了什么问题?我正在使用ApacheXML-RPC版本3.1.2,不幸的是,我发现的示例代码在版本2.x中,不再适用。此外,我在类的开头省略了import语句(当然没有语法错误)。如果有任何帮助,我们将不胜感激。

您的主程序正在结束运行,因为executeAsync会立即返回,而无需等待发送请求或返回响应


通过使用executeAsync,您想实现什么?

我将用一个需要更多时间的函数替换现有的求和函数。因此,我希望调用异步执行。你的“结束”评论也解决了这个问题。我放了一会儿(真的);语句在我的代码的结尾,现在它的工作!
client.executeAsync("sample.sum", params, new ClientCallback());
In error
java.lang.ExceptionInInitializerError
    at java.lang.Runtime.addShutdownHook(Runtime.java:192)
at java.util.logging.LogManager.<init>(LogManager.java:237)
at java.util.logging.LogManager$1.run(LogManager.java:177)
at java.security.AccessController.doPrivileged(Native Method)
at java.util.logging.LogManager.<clinit>(LogManager.java:158)
at java.util.logging.Logger.getLogger(Logger.java:273)
at sun.net.www.protocol.http.HttpURLConnection.<clinit>(HttpURLConnection.java:62)
at sun.net.www.protocol.http.Handler.openConnection(Handler.java:44)
at sun.net.www.protocol.http.Handler.openConnection(Handler.java:39)
at java.net.URL.openConnection(URL.java:945)
at org.apache.xmlrpc.client.XmlRpcSun15HttpTransport.newURLConnection(XmlRpcSun15HttpTransport.java:62)
at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.sendRequest(XmlRpcSunHttpTransport.java:62)
at org.apache.xmlrpc.client.XmlRpcClientWorker$1.run(XmlRpcClientWorker.java:80)
at java.lang.Thread.run(Thread.java:680)
Caused by: java.lang.IllegalStateException: Shutdown in progress
at java.lang.Shutdown.add(Shutdown.java:62)
at java.lang.ApplicationShutdownHooks.<clinit>(ApplicationShutdownHooks.java:21)
... 14 more
public class ClientCallback implements AsyncCallback {

@Override
public void handleError(XmlRpcRequest request, Throwable t) {
    System.out.println("In error");
    t.printStackTrace();

}

@Override
public void handleResult(XmlRpcRequest request, Object result) {
    System.out.println("In result");
    System.out.println(request.getMethodName() + ": " + result);
}
}