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

  • Home
  • SEARCH
  • 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 151137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:24:07+00:00 2026-05-11T09:24:07+00:00

Is it possible to have objects stored in a data structure for the duration

  • 0

Is it possible to have objects stored in a data structure for the duration of an App Server’s uptime? Basically I want an EJB that interfaces with this Data Structure, but does not require a full fledged database solution.

As an example I made this dummy animal object:

package com.test.entities;  public class Animal implements java.io.Serializable {      private static final long serialVersionUID = 3621626745694501710L;     private Integer id;     private String animalName;      public Integer getId() {         // TODO Auto-generated method stub         return id;     }        public void setId(Integer id){         this.id=id;     }     public String getAnimalName(){         return animalName;      }     public void setAnimalName(String animalName){         this.animalName=animalName;     } } 

So here is the EJB Remote Interface:

package com.test.beans;  import java.util.Map;  import javax.ejb.Remote;  import com.test.entities.Animal;  @Remote public interface MapBeanRemote {      public void addAnimal(Animal a);      public void removaAnimal(Integer id);      public Animal getAnimalById(Integer id);      Map<Integer, Animal> getAllAnimals();  } 

Here is the Session Bean:

package com.test.beans;  import java.util.ConcurrentHashMap; import java.util.Map;  import javax.annotation.PostConstruct; import javax.ejb.Stateless;  import com.test.entities.Animal;  @Stateless(mappedName='ejb/MapBean') public class MapBean implements MapBeanRemote{      Map<Integer, Animal> animalStore;      @PostConstruct     public void initialize(){         animalStore = new ConcurrentHashMap<Integer,Animal>();     }      @Override     public void addAnimal(Animal a) {         if(a.getId()!=null){             animalStore.put(a.getId(), a);         }     }      @Override     public Animal getAnimalById(Integer id) {         return animalStore.get(id);     }      @Override     public void removaAnimal(Integer id) {         animalStore.remove(id);      }      @Override     public Map<Integer, Animal> getAllAnimals() {         return animalStore;     }  } 

So basically I want any client who wants to manipulate the Animal Map to go through this EJB and have each client accessing the same exact Map of objects.

This example does not work good enough. After a while all of the animals are erased (I’m assuming when the EJB gets replaced from the bean pool) Could this somehow be injected as a resource?

  • 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. 2026-05-11T09:24:07+00:00Added an answer on May 11, 2026 at 9:24 am

    This can be accomplished by putting the Map in a Singleton and accessing this singleton from the beans. That way there is a single instance for all the EJB instances (since they share the same classloader). Different Session beans in different EAR’s would not work though as they would each have their own classloader, but that doesn’t appear to be your scenario.

    Your existing usage of ConcurrentHashMap will sufficiently handle most of your cases but you still need synchronization around the addAnimal method since you need the map to be consistent between the two method calls.

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

Sidebar

Ask A Question

Stats

  • Questions 158k
  • Answers 158k
  • 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 What prevents you from installing IIS with support for ASP?… May 12, 2026 at 11:13 am
  • Editorial Team
    Editorial Team added an answer Overriding document.write, call the deployment script, and then re-set document.write. May 12, 2026 at 11:13 am
  • Editorial Team
    Editorial Team added an answer You could use an attached property. Create an attached property… May 12, 2026 at 11:13 am

Related Questions

Our win32 application assembles objects from the data in a number of tables in
In the application(C#) I am maintaining, there are some serialized object stored in the
I have a requirement to use business objects to call strongly typed table adapters
I have to port a smaller windows forms application (product configurator) to an asp.net

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.