RPC Services do have timeouts, its just that by default they are set
to 0, which effectively means no timeout.
Here's what you can do to set timeouts on your services -
a) Create a custom RpcRequestBuilder, and set the desired timeout
public class MyRpcRequestBuilder extends RpcRequestBuilder {
@Override
protected RequestBuilder doCreate(String serviceEntryPoint)
{
RequestBuilder builder = new RequestBuilder
(RequestBuilder.POST, serviceEntryPoint);
builder.setTimeoutMillis(RPC_TIMEOUT);
return builder;
}
}
b) Set the custom RpcRequestBuilder immediately after your GWT.create
(..) call
//Can be a global object -- you don't have to create a new one
everytime
RpcRequestBuilder theBuilder = new MyRpcRequestBuilder();
MyServiceAsync service = GWT.create(MyService.class);
((ServiceDefTarget) service).setRpcRequestBuilder(theBuilder);
c) Use the service object to invoke methods as you normally do. In
your AsyncCallbacks onFailure(Throwable t), you can check
if (t instanceof RequestTimeoutException) {
/// handle timeouts..
}
thats it.