VB_
VB_

Reputation: 45692

EJB scalability: due to what

Can you simply explain me due to what the EJB achieves scalability, and which problems I'll face, for example, if I would not use EJB for large application.

Thanks in advance.

Upvotes: 1

Views: 1604

Answers (3)

Tom
Tom

Reputation: 4093

Can you simply explain me due to what the EJB achieves scalability

Scalability is achieved by deploying EJBs in a cluster: http://docs.oracle.com/cd/A97688_16/generic.903/a97677/cluster.htm. In a nutshell: each request will be received by one server in the cluster. This server then decides if it processes the request itself, or forwards it to another server. Which server will process the request is determined by some configurable algorithm, the easiest being round-robin (i.e. the first request goes to server 1, the second goes to server 2, and so on).

However, in my experience it is easier not to do clustering on an EJB-level, but instead at a higher level. That means, that there is an (external) loadbalancer that receives all the requests and forwards them to the application servers containing the EJBs (again by some algorithm like round-robin). The application servers don't have to know each other in this scenario, which is much easier to configure.

In some cases, however, an EJB-level clustering may be necessary, for example if you have stateful session beans that have to support session failover (i.e. when the server the request is currently being processed on crashes, the session has to be moved to another server, so that the user doesn't notice anything). This is rarely necessary, though.

which problems I'll face, for example, if I would not use EJB for large application.

I would suggest using either EJB or Spring as an alternative for a large application. These frameworks take care of the nitty-gritty programming you would other wise have to do yourself, like the following

  • opening and closing transactions
  • providing access to resources (like database connections)
  • dependency injection
  • support for aspect oriented programming
  • and much more...

If you use Spring, you don't even have to deploy to a full-blown application server but can use a simple servlet container instead.

Upvotes: 1

fdreger
fdreger

Reputation: 12495

EJB don't give you any special scalability bonus, and there is no penalty for not using them.

Some of the "EJBs are scalable" hype comes from the days when object pooling was considered a performance booster.

EJB can help you write efficient code in two minor ways:

  • EJB architecture has a way of spreading business logic across a couple of machines (using remote interfaces and JNDI lookup allow you to move processing between servers without modifying code).
  • EJBs will help you get the most of JPA by easily sharing persistence contexts and - in some cases - using the same context for many calls.

But both above goals are achievable without EJBs.

Anyway: you should be using them, because they do make code nicer and easier to maintain. And those two qualities usually help build scalable apps.

Upvotes: 2

Stephen C
Stephen C

Reputation: 718768

I think this question is based on a false premise.

You can't "achieve scalability" through using EJBs ... or any other technologies. Scalability is achieved by designing for scalability; i.e. by avoiding bottlenecks (of various kinds) and avoiding inefficient use of resources.

Upvotes: 0

Related Questions