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 8002919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:30:55+00:00 2026-06-04T16:30:55+00:00

Hi have create a interface as @Remote public interface MathInter{ public int add(int x,

  • 0

Hi have create a interface as

@Remote
public interface MathInter{
    public int add(int x, int y);
    public int  showResult();
}

and the class as

@Stateful(mappedName="test")
public class MathImp implements MathInter{
    public int result;
    public int showResult()
    {
        return result;
    }
    @Override
    public int add(int x, int y) {
        result = x + y;
        return x+y;
    }

}

and used it on a client.jsp

<%!
    @EJB(mappedName="abc")
    MathInter m;
%>

<%
    out.write("previous result was "+m.showResult());
    out.write("result is "+m.add((int)(Math.random()*100), (int)(Math.random()*100)));
%>

The problem is that on Lan, I have 2 computers with IP address as 192.168.1.4 and 192.168.1.2. The server begin 192.168.1.4, when I visit the client.jsp page from the server, a new object of MathImp is created, and then when I access via the other comp, the same object seems to be used

Isn’t it required that a new request for a new client has a new object created?

  • 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-06-04T16:30:57+00:00Added an answer on June 4, 2026 at 4:30 pm

    Shortly: one JSP -> one instance of corresponding Servlet -> EJB injected once -> same instance is shared between all requests, no matter which client.

    Longer explanation:

    No, it is not required that container creates new instance for each new client. But it is required that for each dependency injection (as in your case) and for each JNDI lookup container creates new instance of stateful session bean.

    In your case injection happens only once. That is because container compiles JSP to Servlet and there is only one instance of that Servlet (and consequently injection of ejbs to the fields of that servlet only once) that serves all requests. That’s why same instance of MathInter is shared between all requests.

    If you need per client instances (as is the case with stateful session beans) you should not inject those to servlet, but just for example lookup them and store reference to the HttpSession.

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

Sidebar

Related Questions

I have created and EJB with a remote interface: @Stateless public class TestSessionBean implements
I am trying to create a class that implements the IUnknown interface. I have
I have this interface public interface MyInterface{ Collection<T> Find(T t); Collection<T> FindAll(); T FindById(int
I have a c# class P2PLib. public int portRecv=10101; public int portSend = 10102;
Say I have the following EJB (using ejb3): @Stateless(name=Queries) @Remote(Queries.class) @Local(Queries.class) public final class
In Interface Builder components I have Gradient Button I would like to create this
I have a basic core interface called IComponent. public interface IComponent { void Initialize();
I have a simple data contract: [DataContract] public class MyData { [DataMember] public string
I'm trying to create an EJB factory class, which works like this: You have
I need to create a Mortgage Calculator for my Java class, and I have

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.