my dog learned polymorphism*
The moose likes Servlets and the fly likes Servlets, and garbadge collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlets, and garbadge collection" Watch "Servlets, and garbadge collection" New topic
Author

Servlets, and garbadge collection

Kinga Cserveny
Greenhorn

Joined: Aug 29, 2001
Posts: 18
Hi everyone,
I was wondering if anyone could help me. There is a servlet that creates employee's and stores their details, working hrs, address, payment details etc in a database.
When the servelt was tested to handle 20 users concurrently accessing it, it fell over after about 10 users, because it did not have enought memory. I am still new in the servlet business so I am not sure if I understod the problem properly, but as far as I know the problem is that too many objects were created which caused the garbage collector to go absolutely mad trying to reclaim memory in the background. So now I was asked to come up with a solution to replace statments like Employee emp = new Employee(session, ....).
Can anyone suggest an easy and quick solution ? THanks for anybodies help.
K
sanj singh
Ranch Hand

Joined: Jun 30, 2001
Posts: 129
Hi Kinga
Have you tried using database connection pooling.
regards
sanj
Kinga Cserveny
Greenhorn

Joined: Aug 29, 2001
Posts: 18
Yes but the problem is not just the database connection, I have an object (Employee) which consists of many other objects inside it. Such as PayDetails object, TimeSheet object, WorkignHrs object etc. Which causes too much memory being allocated when a new Object is created, and the garbage collects struggels to reclaim all the memory not being used. Can you suggest anything insted of using new Object()?
thanks K
sanj singh
Ranch Hand

Joined: Jun 30, 2001
Posts: 129
Hi Kinga
Are you storing anything in the session.If you are doing that and there are a large number of users logged in then it will bring down your application on its knees.
regards
sanj
Kinga Cserveny
Greenhorn

Joined: Aug 29, 2001
Posts: 18
Yes I am. So what can I do instead of storing it in the session? What is the problem with storing things in the session?
k
sanj singh
Ranch Hand

Joined: Jun 30, 2001
Posts: 129
Hi Kinga
Here's an example.Say for example each user uses 5 kb of memory then for a million users that amounts to 5 Gbs of memory.
Need i say more.
regards
sanj
Kinga Cserveny
Greenhorn

Joined: Aug 29, 2001
Posts: 18
No.. I get the picture, so what can I do instead of storing them in the session, as I need to store data from everypage before eveluating them and storing them in the database.
thanks
k
 
jQuery in Action, 2nd edition
 
subject: Servlets, and garbadge collection