java - Calling System.gc() causing data loss in JSP -


I am currently debugging a web application which is causing intermittent problems, especially when the hit rate is high as everyone The new user is given a session with the personal navigation menu, so I thought how much memory I would need for the session variable.

In the code section of JSP which handles the creation of session objects, the following code was added:

  System.gc (); Long orgHeap = Runtime.getRuntime (). FreeMemory (); ... Create session variables ... System.gc (); Log.info ("Heap Delta:" + (RuntimeGreat Time (Freemo) - Org Hep.);)  

I'm surprised that Adding System.gc () breaks the app, it does not work much because some objects are losing (or it seems) the values ​​that were started They are zero When GC () calls are removed, the app works fine. GC () should only remove those items that have been marked for removal - is not it? OK << p>

Is anyone else having such a problem?

The only case I can think is where it can be from what it really can be , Is that whether you are using S to render the object (or have ended, which are roughly similar in this situation) that you still want to keep the objects in a state where They are collecting enabled by GC; But as long as it does not really work, you will still be able to reach them through your references. Calling System.gc () , even if there is no guaranteed semantics in it, the collector can run and cut all these weaker-accessible objects.

This seems unlikely, however, because

  1. Using illicit references in awe is not an easy mistake for an object that is firmly reachable. If you are using libraries, then I think it is difficult to think of a case where you can accidentally end weak references.
  2. If this happens then the behavior of the application will be undefined anyway. Garbage collection can happen at any time, so you will likely see incompatible behavior without system.gc () calls. You always have a little code that runs anyway after the collection and hence its receipt is not found.
  3. System.gc () does not do anything theoretically, so it should not be

This last point is important - Why do you system Anyway, gc () are saying , when the call is almost always reversed? I do not believe you have a legitimate need to call it, it does not do anything that can depend on you, and apparently it is breaking your application.

So if your app works fine without calling, then stop stopping it.

I will still check how your app fits together, because this is not the real cause of the problem and you have a deep problem which is very delicate and just waiting for you to break later is.

Edit: Another possible reason for this could be simple time. Calling System.gc () is likely to take a non-negligible amount During this period, other threads can progress and the GCID thread is not expected to change the state in this way You can. So when it returns from the call, then the world's condition breaks its expectations and hence the consequences of logic errors again, this is just an estimate, but WeakReference is more than appreciable.


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -