<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Webxml on despatches</title><link>https://icle.es/tags/webxml/</link><description>Recent content in Webxml on despatches</description><generator>Hugo</generator><language>en</language><lastBuildDate>Fri, 20 Jun 2025 09:25:00 +0100</lastBuildDate><atom:link href="https://icle.es/tags/webxml/index.xml" rel="self" type="application/rss+xml"/><item><title>JBossWS CXF - POJO vs Stateless [1104]</title><link>https://icle.es/2011/11/05/jbossws-cxf-pojo-vs-stateless/</link><pubDate>Sat, 05 Nov 2011 15:32:32 +0000</pubDate><guid>https://icle.es/2011/11/05/jbossws-cxf-pojo-vs-stateless/</guid><description>&lt;p>Cleaning up a bunch of code to reduce object instantiations got me thinking
about the webservice layer. We are using POJO based webservices but it got to me
wondering whether useless Stateless web service beans would improve memory
usage. More accurately, whether it would improve garbage collection performance.&lt;/p>
&lt;p>To test this, the plan was to build two versions of the same web service and
load test it to see the memory and cpu utilisation to compare cost /
performance.&lt;/p>
&lt;p>In the process, I also discovered other differences.&lt;/p></description><content:encoded><![CDATA[<p>Cleaning up a bunch of code to reduce object instantiations got me thinking
about the webservice layer. We are using POJO based webservices but it got to me
wondering whether useless Stateless web service beans would improve memory
usage. More accurately, whether it would improve garbage collection performance.</p>
<p>To test this, the plan was to build two versions of the same web service and
load test it to see the memory and cpu utilisation to compare cost /
performance.</p>
<p>In the process, I also discovered other differences.</p>
<p>Both the web services were built against this interface</p>
```java
@WebService
public interface WSTest {

    @WebMethod
    public String greetClient(String name);

}
```
<p>That is of course a simple enough interface.</p>
<p>The EJB version of this is as follows:</p>
```java
@WebService(endpointInterface = "uk.co.kraya.wstest.WSTest")
@Stateless
@Remote(WSTest.class)
public class EJBWebTest implements WSTest {

    public String greetClient(String name) {
        return "EJB Says Hello to " + name;
    }

}
```
<p>Simple and straightforward enough and the POJO version is not that different</p>
```java
@WebService
public class PojoWebTest implements WSTest  {

    @WebMethod
    public String greetClient(String name) {
        return "Pojo Says Hello to " + name;
    }

}
```
<p>I also used the following web.xml. This may not be a necessary step any more.</p>
```xml
<?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>

        <display-name>Archetype Created Web Application</display-name>
        <servlet>
                <servlet-name>GreetingWebService</servlet-name>
                <servlet-class>uk.co.kraya.wstest.pojo.PojoWebTest</servlet-class>
        </servlet>
       <servlet-mapping>
                <servlet-name>GreetingWebService</servlet-name>
                <url-pattern>/*</url-pattern>
        </servlet-mapping>
</web-app>
```
<p>Now that was complete, there was the deployment to consider. I had assumed that
I could just do one build, package it as an war and just deploy it but as it
turns out, that didn&rsquo;t work. This only deployed the Pojo web service. To deploy
the EJB web service, I had to package it as an EJB (maven) and deploy a jar
file.</p>
<p>This meant that I ended up with two deployments, wstestpojo.war and
wstestejb.jar.</p>
<p>Once deployed, I used SoapUI to load test both the web services and the results
were interesting.</p>
<p>In the grand scheme of things, the difference was pretty minimal between the
two. However, the Stateless EJB web service used a little extra (3% - 5%) CPU
presumably from the pooling of the beans and accessing them.</p>
<p>I used JBoss 5.1 and ran into an issue with log pollution</p>
<p>EJBTHREE-1337: do not get WebServiceContext property from stateless bean
context, it should already have been injected</p>
<p>This was printed every time an EJB based web service was called.</p>
<p>I
<a href="http://idevone.wordpress.com/2009/09/14/howto-suppress-ejbthree-1337-warning/" title="HOWTO: Suppress EJBTHREE-1337 warning">found more information about the EJBTHREE-1337 issue and a workaround for it</a>
The workaround simply involves updating log4j to not log it which is good enough
for me&hellip; :-)</p>
<p>As a final note, I am unsure as to how this would scale with complex web
services that have multiple instantiated objects as part of it.  I have a sneaky
suspicion that web services with expensive object instantiations would perform
better if using Stateless EJB Beans as would web services that are memory
hungry. However, this has not been tested.</p>]]></content:encoded></item></channel></rss>