• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can I invoke Runtime.gc() in an EJB

 
Meet Gaurav
Ranch Hand
Posts: 492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can I invoke Runtime.gc() in an EJB?

As of my knowledge Runtime.getRuntime().gc() is a Java command and we can add it in EJB and we can compile & deploy successfully. while application server executing the line it will request gc. If suppose gc starts then the EJB objects are destroyed ? or any other effect ?

Application server will clear the objects for us rite ?

Any difference bettween Runtime.getRuntime().gc() and System.gc() ?
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Meet Gaurav wrote:Can I invoke Runtime.gc() in an EJB?

Why do you want to do that?

Meet Gaurav wrote:
Any difference bettween Runtime.getRuntime().gc() and System.gc() ?


Javadocs are the best place for such information
 
Ran Pleasant
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Meet Gaurav wrote:Can I invoke Runtime.gc() in an EJB?


With EJBs in an application server your focus should be on business logic, not garbage collection. The server will handle garbage collection at the best time for all of the applications running on it. Stop and think about it, application servers are not just multi-threaded, they are multi-application, if you could get the server to do a garbage collection when you want it to then that garbage collection just might be in the middle of a very critical process in another EJB application or even during a critical process in your own application. Focus on business and leave the plumping to the application server.
 
Meet Gaurav
Ranch Hand
Posts: 492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ran,

I know that.. But this is just an interview question.


Thanks
Casttro
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!