I'm new to web services and am deciding whether or not to implement my
web service as a simple java class or a stateless session ejb. Reading
the weblogic documentation, one line confuses me "Implementing Web
Service by Java Class - write thread-safe code, because WebLogic
maintains only a single instance of a Java class that implements a Web
Service operation, and each invoke uses this same instance"
If two requests from different clients come in at the same time for the
same service, (1) is the second request blocked until the first
succeeds OR (2) are they both run concurrently, but you better take
care that they don't modify some shared resource without
synchronization?
forgive the newbie question, thanks for the help - Dan
Christiansem - 21 Nov 2005 23:18 GMT
I'm new too in Web services, If you find the answers could you send me.
Thanks in advance
Richard Scott Smith - 22 Nov 2005 22:54 GMT
> I'm new to web services and am deciding whether or not to implement my
> web service as a simple java class or a stateless session ejb. Reading
[quoted text clipped - 10 lines]
>
> forgive the newbie question, thanks for the help - Dan
It looks like you are discussing 2 different issues here. You are talking
about implementing your solution with EJBs or not and whether you need to
worry about writing thread safe code.
As far as Weblogic specifically, it is simply a j2ee webserver. All of
them behave the same with regard to threads.
First: EJBs. If your application does not require distribution (over many
servers) or declaritive transaction support, EJB is probably not your best
technology choice. If fact there are much simpler ways of doing
declaritive transactions anyway, like with Spring and Hibernate. I would
consider these before any EJB implementation. EJBs tend to be over-kill
for many projects. If you're willing to invest the time to learn EJBs,
then you can learn Spring and Hibernate to accomplish most web programming
goals.
Second: thread safe-code. This is something you should study and
understand anyway. Weblogic does what most (all the ones I know) servlet
containers do, that is create a single instance and multi-thread it for
performance. One solution is to synchronize methods but that will only
allow one request to be serviced at a time. If this is a low load
situation, this may be okay. But by a large you will want to make sure
that multiple requests to the same objects behave as they should without
synchronization. Performance will be MUCH better and you'll learn one of
the most valuable aspects of programming with Java for web applications!
Good luck,
These are ambitious endeavors! Java Programming, especially for the Web
is non-trivial.

Signature
R. Scott Smith
Slackware Linux on the job, at home, everywhere!
EricF - 23 Nov 2005 05:13 GMT
>I'm new to web services and am deciding whether or not to implement my
>web service as a simple java class or a stateless session ejb. Reading
[quoted text clipped - 10 lines]
>
>forgive the newbie question, thanks for the help - Dan
To answer the question ...
1) No
2) Yes, but only if the implementation is a POJO (not an EJB)
Having said that, you can design your POJO so synchronization is not
necessary. Is that a good thing? It depends.
Here's an example ...
public String handleRequest(String xmlRequest) throws Exception
{
try
{
BizLogic blogic = new BizLogic();
return blogic.service(xmlRequest);
}
catch (Exception e)
{
logger.error("found exception", e);
throw e;
}
}
handleRequest is a method in the POJO that the web service invokes. It
delegates the processing to the BizLogic class, creating a new instance as
needed.
Should the method be in a SLSB? Maybe. If there is a resource that needs to be
managed (maybe a 3rd party license), a SLSB may be a good way to go. Let's
face it - web services are a magnitude of order slower than RMI. So you may
want to make the business logic available as an EJB and a web service.
There may be better approaches than web services or EJB - Spring may be a good
option - but that's a tangent to your question. ;-)
Good luck.
Eric