!!! Storing and Getting data from HashMap !!!
Hi ,
I have got a doubt if this is possible .. Please let me know if this can be implemented ..
I have a Process1 running which stores data into HashMap one by one from the Users.
Eg:
KeyObject
1 > Karthik
2 > Raaghav
3 > Srikanth
and so on ..
Now what i internally do is i will wait for 5 min Duration (Session TimeOut).Once it is Over 5 min I will delete it from HashMap and Store it in a file ..
Iam also using WebServer Eg:Iplanet .
Now when i Shut down Iplanet all the data in the HashMap is Lost .
My Requirement is to write another Process2 which will be invoked as soon as Iplanet is ShutDown and This process has to read the data from HashMap which is not Timed out .And write it into the File ..
Q1)Please Let me know if this is can be Done ..
Task Done :
-
Process1 is already existing
Doubts :
--
Q2)If we write a Process2 will it spawn another VM or it will take the same VM that of the Process1.
Becos if it spawns another VM then I will not be able to get the data from HashMap of the Process1..
Thanks in Advance,
iwishtolearn@rediffmail.com
I'm not sure if I get you right. Are you using servlets (or JSP)? If you are, you could do the following:
redefine the init() and destroy() methods:
private Map myUsers = new HashMap();
public void init() { myUsers.clear(); super.init(); }
public void destroy()
{
// save myUsers in a file.
super.destroy();
}
synchronized void addUserToTheMap( HttpSession session ) { /*Extract the essential data here and add it to myUsers*/ }
call the third method from within the service method.
Do not use other processes, you can do everything within the Servlet.
igarn at 2007-6-29 10:23:22 >

Thank You for the ..
But my prblm is that the Process1 is already Existing which reads and writes in to HashMap ( Not a Servlets) ..Its a Pure Java Code ..
And Now the requirement is another Process2 lets say which is put in thread (running in background )which gets the data from the HashMap of the Process1 or in other words Use the Same HashMap and not a different One ...
Process1 >HashMap
(write.java)(writes data )/\
|
|
|(get Data)
|
|
|
Process2
I hope iam clear with my requirement ..
If Any further explanation Required Iam perpared to give ..Please let me know
thanks in advance ..