java:thelastpacketsuccessfullyreceivedfromserver
                Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| java:thelastpacketsuccessfullyreceivedfromserver [2013/10/02 07:22] – rlunaro | java:thelastpacketsuccessfullyreceivedfromserver [2022/12/02 21:02] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== The last packet successfully received from the server was X milliseconds ago ====== | ====== The last packet successfully received from the server was X milliseconds ago ====== | ||
| - | |||
| - | |||
| - | ===== This is a work in progress ===== | ||
| - | |||
| - | I've detected that this page receives many visits. Unfortunately, | ||
| ===== Intro ===== | ===== Intro ===== | ||
| - | This problem is driving me mad since more than three months. I've tried many things to find out a solution, but at the present moment (30/ | + | ==== This crap will be useful  | 
| - | + | ||
| - | However, **I am creating this page to register all the solutions and as an advice for other people.** | + | |
| - | + | ||
| - | ==== This crap is useful if you... ==== | + | |
|   * Have tried the well known solutions: [[http:// |   * Have tried the well known solutions: [[http:// | ||
| Line 22: | Line 13: | ||
| * Mysql worked perfectly | * Mysql worked perfectly | ||
| * There wasn't a network error | * There wasn't a network error | ||
| - | * So... what is the problem??? | + |   * So... were the problem  | 
| ==== My architecture ==== | ==== My architecture ==== | ||
| Line 28: | Line 19: | ||
| Before going on, I think it's important to describe what's my architecture. If it doesn' | Before going on, I think it's important to describe what's my architecture. If it doesn' | ||
| - | * Mysql as persistence engine (I love this: persistence engine. In my times this was simple a RDBMS, but now... wow! it's a persistence engine!) | + | * Mysql as database | 
| * C3P0 as connection pooling mechanism | * C3P0 as connection pooling mechanism | ||
| * Hibernate as data access layer | * Hibernate as data access layer | ||
| Line 34: | Line 25: | ||
| * A batch application that runs for hours and then stops. It only have one thread: starts, do thounsands of queries and then stops. | * A batch application that runs for hours and then stops. It only have one thread: starts, do thounsands of queries and then stops. | ||
| - | PENDIENTE: INDICAR AQUÍ LOS DETALLES DE LA CONFIGURACION HIBERNATE Y C3P0 | + | If you have the same problem, but in a web application, | 
| ===== First approach: retention of Session objects ===== | ===== First approach: retention of Session objects ===== | ||
| Line 285: | Line 275: | ||
| </ | </ | ||
| - | **An this is wrong.** The [[http:// | + | **An this is wrong.** The [[http:// | 
| However, I am starting to think that HibernateTemplate doesn' | However, I am starting to think that HibernateTemplate doesn' | ||
| Line 332: | Line 322: | ||
| + | ===== My final configuration of Spring ===== | ||
| + | |||
| + | First, define C3P0 datasource: | ||
| + | |||
| + | < | ||
| + | <!-- | ||
| + | A better datasource: it gives a new connection each time | ||
| + | is requested. | ||
| + | --> | ||
| + | 	  <bean id=" | ||
| + | 	        class=" | ||
| + | 	        destroy-method=" | ||
| + | 	        scope=" | ||
| + | <!-- | ||
| + | To test a connection: | ||
| + | mysql -h HOSTNAME -u USERNAME -p | ||
| + | and aftwerwards introduce the password when requested | ||
| + | |||
| + |         | ||
| + |       < | ||
| + |       < | ||
| + |       < | ||
| + |       < | ||
| + | <!-- | ||
| + |       Recommended values for maxPoolSize and minPoolSize: | ||
| + | 1. get value of max available connections of your | ||
| + |               | ||
| + |           2. this will be the upper limit for maxPoolSize: | ||
| + | reach never this limit | ||
| + | 3. check out with show processlist the active connections | ||
| + | to the database: this will help to determine the available | ||
| + |               | ||
| + | (show processlist) - (show variables like max_connections) | ||
| + | 4. it is advisable to identify how many DAO objects will be | ||
| + |               | ||
| + | make a rough stimation. Say that this value will be | ||
| + | 10. A good and steady value for maxPoolSize can | ||
| + | be 40 (four times). | ||
| + | |||
| + |         | ||
| + | 			< | ||
| + | 			< | ||
| + | <!-- | ||
| + | checkoutTimeout mits how long a client will wait for a | ||
| + | 			Connection, | ||
| + | cannot be supplied immediately. In milliseconds. | ||
| + | 			http:// | ||
| + | --> | ||
| + | 			< | ||
| + | 			< | ||
| + | 			< | ||
| + | 			<!-- property name=" | ||
| + | <!-- | ||
| + | testConnectionOnCheckout is not recommended because it | ||
| + | checks the connection before give it to hibernate. In a | ||
| + | paranoid environment could fix some problems | ||
| + | --> | ||
| + | 			<!-- property name=" | ||
| + | <!-- | ||
| + | debugUnreturnedConnectionStackTraces prints a stack trace when | ||
| + | a connection that is given to hibernate reachs its timeout value. | ||
| + | This could help to debug cases when a connection is taken and | ||
| + | not released in a certain amount of time | ||
| + | 			http:// | ||
| + | --> | ||
| + | 			<!-- property name=" | ||
| + | <!-- | ||
| + | unreturnedConnectionTimeout is the silver bullet for a problem in | ||
| + | a greedy application (in terms of sessions). It will count how long | ||
| + | hibernate has taken a connection, and if reachs a timeout, c3p0 will | ||
| + | replace this connection with a fresh session, avoiding the problem | ||
| + | of the database may close opened for much time | ||
| + | 			http:// | ||
| + | --> | ||
| + | 			< | ||
| + | 	  </ | ||
| + | |||
| + | </ | ||
| + | |||
| + | |||
| + | Second, the hibernateTemplate and jdbctemplate objects of spring will be available accross the application. | ||
| + | **Beware!!! If you are developing a web application, | ||
| + | |||
| + | |||
| + | <code xml> | ||
| + | 	  <bean id=" | ||
| + | 	        class=" | ||
| + | 	        scope=" | ||
| + | 	    < | ||
| + | 	  </ | ||
| + | |||
| + |     <bean id=" | ||
| + |           class=" | ||
| + |           scope=" | ||
| + |         < | ||
| + |     </ | ||
| + | |||
| + | </ | ||
| + | |||
| + | Finally, the sessionFactory: | ||
| + | |||
| + | <code xml> | ||
| + |     <bean id=" | ||
| + |           class=" | ||
| + |           scope=" | ||
| + |         < | ||
| + |         < | ||
| + |             < | ||
| + |                 < | ||
| + |                 < | ||
| + |                 < | ||
| + |                 < | ||
| + |                 < | ||
| + |                 < | ||
| + |             </ | ||
| + |         </ | ||
| + |         < | ||
| + |             < | ||
| + |                 <prop key=" | ||
| + |                 <!-- for debug, put these values to " | ||
| + |                 <prop key=" | ||
| + |                 <prop key=" | ||
| + | |||
| + | <!-- | ||
| + | Possible values for this are: | ||
| + |                       | ||
| + | the first time it requires it and release it when it's | ||
| + | destroyed | ||
| + |                       | ||
| + | session is released after Transaction issues a commit or | ||
| + | rollback | ||
| + |                       | ||
| + | connection is released after execution of every statement, | ||
| + | BUT it will keep the connection open if the object | ||
| + |                   | ||
| + |                 <!-- prop key=" | ||
| + |             </ | ||
| + |         </ | ||
| + |     </ | ||
| + | |||
| + | </ | ||
| + | |||
| + | I've put plenty of comments of useful configuration parameters and lots of information, | ||
| + | ===== Resources ===== | ||
| + | http:// | ||
| ~~DISQUS~~ | ~~DISQUS~~ | ||
java/thelastpacketsuccessfullyreceivedfromserver.1380698541.txt.gz · Last modified: 2022/12/02 21:02 (external edit)
                
                