Java 如何将方法转换为web服务的异步方法?
我目前有一个工作正常的web soap服务方法,但我想知道如何将其转换为返回消息已被接收以及客户端不会等到我完成该过程的确认Java 如何将方法转换为web服务的异步方法?,java,web,soap,soap-client,Java,Web,Soap,Soap Client,我目前有一个工作正常的web soap服务方法,但我想知道如何将其转换为返回消息已被接收以及客户端不会等到我完成该过程的确认 @Service @WebService(serviceName = "getStudents",wsdlLocation="/wsdl/Students.wsdl") public class StudentsImpl implements Students { public StudentResponse getStudents(StudentRe
@Service
@WebService(serviceName =
"getStudents",wsdlLocation="/wsdl/Students.wsdl")
public class StudentsImpl implements Students {
public StudentResponse getStudents(StudentRequest
request) {
**********************
}
}
public class StudentResponse
{
private String status;
private Date timeStamp;
....................
}
我想知道我如何回复“OK”状态和时间
@WebService
public abstract interface Students
{
@WebResult(name="response")
@XmlElement(required=true, name="request")
public abstract StudentResponse
getStudents(@WebParam(name="request") StudentRequest
request);
}
嗯,有趣的是,这似乎与我回答的最后一个问题相反 因此,这些步骤是:
- 在新线程中执行阻塞调用
- 引入侦听器接口
- 当阻塞调用完成时,从线程调用侦听器
- 引入一个可以从调用方调用的新异步包装器
fooBlocking()
,请执行以下操作:
public class MyKoolClass {
// .. kool functionalities here ...
public interface Listener {
void onTaskCompleted(String message);
}
public void fooAsyncWrapper() {
new FooTask(new Listener() {
@Override
public void onTaskCompleted(final String message) {
System.out.println("So complete, bruh" + message);
}
}).start();
}
public static class FooTask extends Thread {
Listener listener;
public FooTask(final Listener listener) {
this.listener = listener;
}
@Override
public void run() {
fooBlocking();
listener.onTaskCompleted("Sup baws.");
}
}