Advertisement
Guest User

commons-pool

a guest
Jan 22nd, 2014
404
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. INSIDE SERVLET:
  2.  
  3. FondipFactory fondipFactory = (FondipFactory) getServletContext().getAttribute("FondipFactory");
  4.  
  5. BusinessDelegate businessDelegate = new BusinessDelegateWorkPooled(fondipFactory.borrowFondipClient());
  6.  
  7. AderenteTO aderente = businessDelegate.getAderente(codiceFiscale);
  8. ....
  9.  
  10. fondipFactory.returnFondipClient(businessDelegate.getFondip()); //ERROR:
  11.  
  12. java.lang.IllegalStateException: Returned object not currently part of this pool
  13. 15:03:52,681 ERROR [STDERR] at org.apache.commons.pool2.impl.GenericObjectPool.returnObject(GenericObjectPool.java:534)
  14. 15:03:52,681 ERROR [STDERR] at it.icbpi.fondip.ui.utili.FondipFactory.returnFondipClient(FondipFactory.java:39)
  15. 15:03:52,682 ERROR [STDERR] at it.icbpi.fondip.ui.servlet.ProfileServlet.doPost(ProfileServlet.java:66)
  16.  
  17.  
  18.  
  19.  
  20. FONDIPFACTORY CLASS:
  21.  
  22.  
  23. public class FondipFactory {
  24. private GenericObjectPool<Fondip> fondipPool;
  25.  
  26.  
  27. public FondipFactory(GenericObjectPool<Fondip> pool) {
  28. this.fondipPool = pool;
  29. this.fondipPool.setMaxTotal(10);
  30. //this.fondipPool.setMaxIdle(0);
  31. // setMaxActive(1000);
  32. }
  33.  
  34. public ObjectPool<Fondip> getFondipPool() {
  35. return fondipPool;
  36. }
  37.  
  38. public void setFondipPool(
  39. GenericObjectPool<Fondip> fondipPool) {
  40. this.fondipPool = fondipPool;
  41. }
  42.  
  43.  
  44.  
  45. //extract from pool
  46. public Fondip borrowFondipClient() throws Exception {
  47. return fondipPool.borrowObject();
  48. }
  49.  
  50. //return the object to the pool
  51. public void returnFondipClient(Fondip fondip) throws Exception {
  52. fondipPool.returnObject(fondip);
  53. }
  54. }
  55.  
  56. CLASS BUSINESSDELEGATEWORKPOOLED
  57.  
  58. public class BusinessDelegateWorkPooled implements BusinessDelegate {
  59.  
  60.  
  61. private Fondip fondip;
  62.  
  63. public BusinessDelegateWorkPooled(Fondip fondip) {
  64. this.fondip = fondip;
  65. }
  66.  
  67. public Fondip getFondip() {
  68. return fondip;
  69. }
  70.  
  71. public AderenteTO getAderente(String codiceFiscale) {
  72. AderenteTO aderenteTO = fondip.getAderente(codiceFiscale);
  73. return aderenteTO;
  74. }
  75. ....
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement