• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Servlets Vs. EJB

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why should i use EJB, when i can do all those functionalities using servlets..?? Even servlets provide me multi-thread model.. to cater to multiple users accessing my buisness logic. Furthermore, i can have a servlet directly talk to database, using a typical 3-tier architecture(UI->servlet->database), then why do i need to incorporate few more layers..(UI->servlets->session-beans->entitybeans->databse). I basically want to know what are the performance advantages of using so many components when a single servlet can serve my purpose.
 
Ranch Hand
Posts: 358
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
EJB takes care of transaction management�The EJB container vendor is required to provide transaction control. The EJB developer who is writing the business functionality need not worry about starting and terminating transactions.
EJB provides distributed transaction support�EJB provides transparency for distributed transactions. This means a client can begin a transaction and then invoke methods on EJBs present within two different servers, running on different machines, platforms, or Java virtual machines. Methods in one EJB can call methods in the other EJB with the assurance they will execute in the same transaction context.
 
Alok Srivastava
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi parmeet thanks for your justification of using EJB over servlets. If for a moment u ignore these fancy words like "transaction monitoring","content management","distributed object model" and come to the ground reality of actual code development, what are the issues involved...??? Firstly if i am using BMP(bean managed persistence) i have to write actual sql queries.. as i need to do in a servlet... but in addition i have to make a remote, home and PKclass, deployment descriptors.. which is definetly an overhead. As far as locking on databse access is concerned in case of different users accessing the same database, i think almost all of the rlational dtabse, like Oracle, sybase etc. provides this feature. so i don't need to bother about this whether i do my job thru' a servlet or EJB. Now if am using a CMP(container managed persistence) how do i make join queries involving multiple tables... for that i will need a tool like toplink to handle that issue, whihc i definetly don't need in case of servlets. Futher more.. as far as interaction between beans from different JVM's are concerned, how do i do that.. without adding anything to my code..??? its impossible... what i need is an RMI.. which i can do even in case of servlets...
So if i think from the coding perspective i find.. the EJB approach more complicated... !!!

 
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Originally posted by Alok Srivastava:
Firstly if i am using BMP(bean managed persistence) i have to write actual sql queries.. as i need to do in a servlet... but in addition i have to make a remote, home and PKclass, deployment descriptors.. which is definetly an overhead.


Although there are overheads of creating more classes with EJB, it is still worth it.Reasons-You are seperating serious business logic from Presentation.By serious, I mean those processes, which are very much data/business-intensive in nature.
If you look at Servlets/JSP, it is nothing but a HTML rendering software.It cannot take the place of Enterprise Applications/Beans like Credit Validation, Credit Processing System, Financial Authorization System and other data-intensive processes.
The data processed by these EJB could be formated by the JavaBeans/Taglibs/Servlets/JSP's to do some minor processing (probably to format it in the manner required by the client!!) and present it to them.


Originally posted by Alok Srivastava:
As far as locking on databse access is concerned in case of different users accessing the same database, i think almost all of the rlational dtabse, like Oracle, sybase etc. provides this feature. so i don't need to bother about this whether i do my job thru' a servlet or EJB.


Would you like to take care of multiple clients accessing your records simultaneously?Would you like to provide Threading feature in your code (and thus hamper performance!!), when you have a technology in place which can do this for you.
Do you wish to code to cache the data in your web server, to take care of DIRTY READS,REPEATABLE READS and PHANTOM READS?Won't this increase your code?Also, will your focus not get diverted to handle these low-level services instead of concentrating on implementing the business requirement?


Originally posted by Alok Srivastava:
Now if am using a CMP(container managed persistence) how do i make join queries involving multiple tables... for that i will need a tool like toplink to handle that issue, whihc i definetly don't need in case of servlets.


Joining mutiple tables maynot be possible in J2EE reference implementation.But it you take any good Application Server, it provides this functionality.I know IBM WebSphere Application Server, which allows this.Also, Oracle has come out with an excellent technology called "Business Components for Java" which is based on the lines of EJB, which not only provides a feature for joining mutiple tables, but also provides validation for the records selected.I am sure there may be many more Application Servers available in the market, which provides better functionality.
If you consider doing this with servlets, how would you manage synchronization of data across distributed databases. You would need to use JTA (another J2EE technology) and two-phase commit to tackle this.Would you like to implement the Resource Managers and the Transaction Managers to manage the synchronization of data.Why not leave it to the expert - J2EE?


Originally posted by Alok Srivastava:
Futher more.. as far as interaction between beans from different JVM's are concerned, how do i do that.. without adding anything to my code..??? its impossible...what i need is an RMI.. which i can do even in case of servlets...


What about applications written in different languages say Java and C++?How are you going to make it talk by using servlets?You will need RMI-IIOP protocol.J2EE containers provides these services implicitly and are better suited to handle such calls.
Hope this give some justification on the use of EJB and servlets.I believe, they are complimenting technologies, not replacements of each other.
Hope this helps,
Sandeep

  • Sun Certified Programmer for Java 2 Platform Scored 93 per cent
  • Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java Scored 56 out of 59
  • IBM Enterprise Connectivity with J2EE Scored 72 per cent
  • Enterprise Development on the Oracle Internet Platform Scored 44 out of 56

  • [This message has been edited by Desai Sandeep (edited May 15, 2001).]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic