# AsyncProvider

Web Service endpoints may choose to work at the XML message level by implementing the `Provider` interface. The related information about `Provider` endpoints is documented in page. However `Provider` endpoints are synchronous i.e. they receive XML requests and they return XML responses synchronously in `invoke()` method. If the endpoint wants to spawn a thread to process the request, it would block the jax-ws runtime thread and has to manage all the low details synchronizing the threads when the response is available. Also blocking a thread doesn't really scale well especially when the underlying transport is capable of handling asynchronous request and responses. RI provides an implemention specific solution to this problem by introducing `AsyncProvider.` This is similar to `Provider` endpoints but the difference is that the endpoint implementations have to implement `AsyncProvider` interface.

## `AsyncProvider` Example

The following example shows an `AsyncProvider` example that accesses the payload of the request.

    @WebServiceProvider
    public class AsyncProviderImpl implements AsyncProvider<Source> {

        public void invoke(Source source, AsyncProviderCallback cbak,
                           WebServiceContext ctxt) {

            // ...

        }

    }

## `AsyncProvider` sample

See a `samples/asyncprovider/Readme.txt` that illustrates `AsyncProvider` endpoints.

## `AsyncService` sample

See another `samples/asyncservice/Readme.txt"` sample that illustrates `AsyncProvider` endpoint that uses asynchronous servlet as the transport to bring true asynchronity on the server-side. See New Asynchronous Servlet Transport in JAX-WS RI for more details on this feature.