will instances of the bean in memory take up ram?
1 posts in topic
Flat View  Flat View

Posted By:   paul_martin
Posted On:   Thursday, March 27, 2003 10:32 PM

I'm studying for an exam on EJB, and I'm reading that

'each entity bean has an underlying table in a

relational database, and each instance of the bean

corresponds to a row in that table.'

Wouldn't that mean that, if, for example, you had

500000 rows in your database, you would have 500000

instances of the bean in memory? Wouldn't that be

expensive in terms of RAM usage?

Re: will instances of the bean in memory take up ram?

Posted By:   Nick_Maiorano  
Posted On:   Saturday, March 29, 2003 06:33 AM


You're forgetting one thing: not all rows in the table are needed at the same time. Usually, when you queury the database, you qualify your search with a where clause so that a limited number of rows (and entity beans) are returned. If, on the other hand, you truly need to read half a million rows, you'd be better off with jdbc cursors.

As far as being expensive in terms of RAM usage, remember that the EJB container manages a pool of anonymous entity beans. Beans are taken out of cache and assigned to specific rows by the container and are placed back into the cache when the transaction completes. So while this consumes memory, it speeds up the process of getting data in and out of the database. For read-only entity beans, it allows rows to be cached and represented as entity beans without ever going to the database.

About | Sitemap | Contact