singleton class/member

V

Vishu

Hi Folks,

I am facing a problem with (Static member) hashmap in a singleton
class. I have a class (Say B, a servlet) that is loaded into memory
during the server's startup. This performs some booking tasks every 10
mins and keeps updating another class (Say A) which is a singleton
class and which has a static hashmap as its member. So the servlet is
updating the data say every 10 mins. Now everything is OK when I access
the servlet over the web (I get the required data; all the servlet does
is, lookup the content in the static hashmap and serve it to the user).
But I am facing a problem when a class (Say C) in a different web
application context (on the same server) is trying to get some data
from the single class A. It passes the same request parameter as the
servlet (class B) does in the initial application, but from class C,
when I try to lookup the hashmap, I dont find any entry for the same
key.. Why is this..?

Thanks!!
 
A

Andrea Desole

Vishu said:
Hi Folks,

I am facing a problem with (Static member) hashmap in a singleton
class. I have a class (Say B, a servlet) that is loaded into memory
during the server's startup. This performs some booking tasks every 10
mins and keeps updating another class (Say A) which is a singleton
class and which has a static hashmap as its member. So the servlet is
updating the data say every 10 mins. Now everything is OK when I access
the servlet over the web (I get the required data; all the servlet does
is, lookup the content in the static hashmap and serve it to the user).
But I am facing a problem when a class (Say C) in a different web
application context (on the same server) is trying to get some data
from the single class A. It passes the same request parameter as the
servlet (class B) does in the initial application, but from class C,
when I try to lookup the hashmap, I dont find any entry for the same
key.. Why is this..?

if it's a different application context it's probably using a different
class loader. Make sure the class loader is the same.
 
V

Vishu

Yes.. Andrea, .. I checked and that is the case.. Do you know of any
way to have communication with the servlet on the same server but in a
different application context..

thanks..
 
A

Andrea Desole

Vishu said:
Yes.. Andrea, .. I checked and that is the case.. Do you know of any
way to have communication with the servlet on the same server but in a
different application context..

Different from communication between two different servers? No. Sorry.
 
M

Manish Pandit

Hi,

You cannot access anything beyond the application context, which will
not work in your case as you're trying to access a class
cross-application.

What you might want to try is, either use some protocol (like HTTP GET
on the provider servlet's URL), or keep serializing the object every 10
minutes at a known location where the other application can read it
whenever needed. If your other app needs to write to it, it needs to
serialize the object as well.

-cheers,
Manish
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

> Yes.. Andrea, .. I checked and that is the case.. Do you know of any
> way to have communication with the servlet on the same server but in a
> different application context..

Put the jar file containing the singleton class in a
directory shared by the web apps.

Arne

PS: But two web apps should not share info like that. Very
likely the correct solution would be to merge the web apps.
 
V

Vishu

thanks folks for the replies. I realized the design flaw and rectified
i by having the class A in the same application context as class B.
Basically, class A is a webservice interface. I configured the
webservice to be a part of my web-app (not separately) and thats it.. !

Yes. I currently have a filesystem based solution where I can serialize
the object and de-serialse.. but i wanted some memory resident
solution.. thats why singleton class.. and a webservice..

THanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,270
Latest member
TopCryptoTwitterChannels_

Latest Threads

Top