Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 380739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:01:05+00:00 2026-05-12T15:01:05+00:00

The @EJB annotation can be use in managed clients to access an EJB. One

  • 0

The @EJB annotation can be use in “managed clients” to access an EJB.

One can place this annotation in a servlet class, declaring a member variable.

public class MyServlet extends HttpServlet {
     @EJB
     private MyWorkerInterface theWorker;
}

That @EJB annotation is expanded to JNDI lookups that (I assume) are executed when the servlet initialises. Those JNDI lookups might fail: the EJB provider can choose to modify their annotations to specify particular JNDI names, my @EJB reference would then need to specify the non-default JNDI name or the lookup would fail.

Also I guess, as the EJB can be remote there is the possibility of transient, network failures and server-bounce errors.

My thought: when using theWorker, I should check for its validity.

  if ( theWorker == null ) {
      // ... etc.

My questions:

1.) Are such null checks necessary?

2.) If they are, and the nulls may be caused by a transient error such as a temporary failure of the remote server, is any recovery possible? The servlet is now intialised. Do I really need to restart my servlet in order to recover? Surely not?

3.) Tentative thought: Explicit, lazy, JNDI lookup code may be needed in preference to using @EJB. Comments?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T15:01:05+00:00Added an answer on May 12, 2026 at 3:01 pm

    Sorry for not giving any references to specs, I’m only speaking from previous experience with JBoss.

    1) No, unless the container made a mistake.
    2) Not relevant, your instance will be a proxy to the remote service, implementing the remote interface. The injection will therefore always succeed. The error will arise when you call the methods of the proxy, so you need to be prepared to handle those errors when using the remote interface. That is what RemoteException was intended for, all errors should be wrapped in a RemoteException for you to catch if something goes wrong. If you let it propagate, the tx will be rolled back, which is a sane default if you manipulate tx-enabled resources only.
    3) This is usually only needed if you need different initial context properties for the JNDI lookup, but for these cases I would personally use a DI engine and another annotation (@EJBFromHost2 for instance). Using explicit JNDI lookups gets very kludgy, especially if you later want to change to another JNDI implementation or settings (if you want to cluster your app for instance).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 387k
  • Answers 388k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer A Servlet container is basically a web server for Java… May 15, 2026 at 12:17 am
  • Editorial Team
    Editorial Team added an answer It looks like Freebase, perhaps in combination with DBpedia, might… May 15, 2026 at 12:17 am
  • Editorial Team
    Editorial Team added an answer If Dir("file_location_1") <> "" Then ''# File is in 1… May 15, 2026 at 12:16 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.