Announcement Announcement Module
No announcement yet.
Replacing a bean instance with another in the Context Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Replacing a bean instance with another in the Context

    Hi all,

    my application is connecting to a server using a pool of connection(apache commons pool) but what i have noticed that the server is cutting the connection(after a given period) even if it still used. And since i don't want to create new connection every time i want to connect, I thought of replacing the pool of connection dynamically to avoid the problem of connection losing.

    Is it possible to do it using ApplicationContextAware?
    and if not any idea about how to do it?

  • #2
    So you want to periodically replace the whole connection pool bean with a new connection pool full of new connections?

    That approach doesn't seem architecturally sound. If your pool is having difficulty managing connections because the server periodically shuts these connections down, then it would be preferable to find or create a more flexible connection-management solution, rather than let the solution to the problem bleed through into an external component.

    To make an analogy, if your car's water pump stopped circulating coolant, you wouldn't compensate for this by modifying other aspects of the cooling system. You'd simply replace the water pump.

    So the bottom line is that it's probably a more effective strategy to find an alternate means of managing the connection pool. Maybe something other than Commons Pool fits the bill. Or maybe, you need to do a little coding to decorate/proxy the pool bean with some custom behavior.