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

Servlets, and garbadge collection

 
Kinga Cserveny
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kinga
Have you tried using database connection pooling.
regards
sanj
 
Kinga Cserveny
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic