[Lab] Making the Java SE Endpoint Publisher Multithreaded

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.

 

Steps for making the Endpoint publisher multithreaded

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.

 

Advantage of this approach

An advantage of this approach is that, the details of thread management do not intrude at all into the publisher.

 

Limitation of this approach

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

Thanks for this article. It is very usefull

Was it useful?

Search the Web

Custom Search

Searches whole web. Use the search in the right sidebar to search only within javajee.com!!!