Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Lossing my session objects

 
Mike DeStefano
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I seem to be losing my session objects -- and my mind -- (but not the session itself).
With each request, I check for the existence of a Login object in the user's session. This works for a random amount of time, and then poof, the object is gone.
I know this so far -
The request.getSession(true) returns the same session as in previous requests. I know this because the session id is the dame, and isNew() is false.
session.getAttribute("login") returns null.
I don't know why I am losing the object and only the object.
Other things of note-
In my web.xml file I set the session-timeout to 3 hours. I lose the object after a few requests -- I don't see a pattern in the number of requests before losing the object, and there is no pattern of time that I lose them after.
I do not implement java.io.Serializable in my Login object (which may be a cause, but I thought this was only for keeping object persistence through server shutdowns and crashes).
I also saw a message in the log regarding a FIleNotFoundException on SESSIONS.ser....
Any thoughts as to what is going on? Is my object in the session being garbage collected or something? Do I need to implement java.io.Serializable (I don't seem to need it when testing on my PC)? If I am missing the SESSSIONS.ser file, is that my server admin's fault?
I hope someone can clear this confusion up for me.
Thanks in advance for any advice...
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would say that message and your symptoms indicates that your object needs to be serializable. Somewhere in the logs there is probably a note about inability to serialize an object. Nothing in the API says the servlet engine has to keep the session in memory.
Bill
 
Mike DeStefano
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the reply... I appreciate it.
I did not realize that they were being stored in memory if I did not implement java.io.Serializable. I thought all simple objects could be serialized.
Would you say, then, that all objects put in a Session object should implement java.io.Serializable?
 
Mark Stein
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike, what server are you using? I know that Weblogic 6.0 (or was it 6.1) had a problem using regular cookies and session cookies. You'd end up with a new session on a random, but regular basis. It drove us crazy until we were able to track it down.
MS
 
Mike DeStefano
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is interesting and would definately be a problem if that is the case here.
My webhost (uniqhost.com) is using Tomcat 4. I am using Tomcat for testing on my machine, and have never encountered this problem, until I uploaded my application, of course (go figure). And it is definately driving me crazy.
I hope I am not having the problem you spoke of, but will definately take it into consideration,
Thanks!
 
Bruce Jin
Ranch Hand
Posts: 672
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just noticed the following error in my Tomcat log file:
( inner MRCPS.MRC924Lbz$Field is a very simple class that does not implements serializable).
Do we always need to serialize object?
Thanks.

Cannot serialize session attribute fieldsarray for session E091F0F4B2C5438502A7A39183C313E7
java.io.NotSerializableException: MRCPS.MRC924Lbz$Field
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1054)
at java.io.ObjectOutputStream.writeArray(ObjectOutputStream.java:1224)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1050)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:278)
at org.apache.catalina.session.StandardSession.writeObject(StandardSession.java:1340)
at org.apache.catalina.session.StandardSession.writeObjectData(StandardSession.java:827)
at org.apache.catalina.session.StandardManager.unload(StandardManager.java:507)
at org.apache.catalina.session.StandardManager.stop(StandardManager.java:654)
at org.apache.catalina.core.ContainerBase.stop(ContainerBase.java:1184)
at org.apache.catalina.core.StandardContext.stop(StandardContext.java:3440)
at org.apache.catalina.core.ContainerBase.removeChild(ContainerBase.java:983)
at org.apache.catalina.core.StandardHost.remove(StandardHost.java:789)
at org.apache.catalina.startup.HostConfig.undeployApps(HostConfig.java:843)
at org.apache.catalina.startup.HostConfig.stop(HostConfig.java:803)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:467)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:155)
at org.apache.catalina.core.ContainerBase.stop(ContainerBase.java:1151)
at org.apache.catalina.core.ContainerBase.stop(ContainerBase.java:1163)
at org.apache.catalina.core.StandardService.stop(StandardService.java:435)
at org.apache.catalina.core.StandardServer.stop(StandardServer.java:534)
at org.apache.catalina.startup.Catalina.start(Catalina.java:794)
at org.apache.catalina.startup.Catalina.execute(Catalina.java:681)
at org.apache.catalina.startup.Catalina.process(Catalina.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:243)
 
Kees van Oosterhout
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The objects have to be serialized when a session is migrating to another VM, i think. Or maybe it is a low memory issue. Check if your web.xml has the <distributable/> tag. If it does, remove it and try again.
Hope it helps.....
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cannot serialize session attribute fieldsarray for session E091F0F4B2C5438502A7A39183C313E7
java.io.NotSerializableException: MRCPS.MRC924Lbz$Field

That sounds like your problem alright. I bet the sevlet engine is trying to conserve memeory by writing out sessions, then hits this error.
If your object just contains primitives and serializable objects such as Strings, you can probably just implement Serializable.
Bill
 
DC Dalton
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This has to be (another) tomcat bug as I am doing complete site security on another site that uses Resin have never had a problem (even with 2000 users on at one time) Have you checked jakarta's site for bug reports??
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic