Engineering Full Stack Apps with Java and JavaScript
The Java SE Endpoint Publisher supports end-point multithreading without much programmer work.
An Endpoint object has an Executor property defined with standard get/set methods.
An executor is an object that executes Runnable tasks such as java Thread instances. An executor is a nice alternative to thread instances, as the Executor provides high level constructs for submitting and managing tasks that are to be executed concurrently.
1. The first step to making the Endpoint publisher multithreaded is to create an executor class.
We can extend ThreadpoolExecutor for trying it out:
class MyExecutor extends ThreadpoolExecutor {//add code}
Most extensions of ThreadpoolExecutor class override one or more of the protected hook methods.
2. In the Endpoint publisher class, we then create an Endpoint instance as:
Endpoint endpoint = Endpoint.create (new SIB());
3. Next, set the Executor as:
endpoint.setExecutor (new MyExecutor());
4. Finally publish the url as:
endpoint.publish(url)
Refer to and make changes to the Publisher class in ‘Writing a simple SOAP Web Service bottoms up’ if you want to try it out.
An advantage of this approach is that, the details of thread management do not intrude at all into the publisher.
The multithreaded Endpoint publisher is suited for light weight production, however a web container such as Tomcat is better suited to publish multiple web services.
Comments
Congratulations
Thanks for this article. It is very usefull