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/09/30 14:46] – [Second Approach: don't relax yourself] 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: | |
| - | ===== First approach: | + | |
| Yes, I am new in hibernate and I miss out this: | Yes, I am new in hibernate and I miss out this: | ||
| Line 258: | Line 248: | ||
| </ | </ | ||
| - | ===== Second Approach: | + | ===== Second Approach: |
| After this, **sometimes I have the same problem, others I get this error**. | After this, **sometimes I have the same problem, others I get this error**. | ||
| Line 271: | Line 261: | ||
| at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java: | at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java: | ||
| </ | </ | ||
| + | |||
| + | ==== HibernateTemplate must be a singleton ==== | ||
| + | |||
| + | Catch it!!! I had this: | ||
| + | |||
| + | < | ||
| + | <bean id=" | ||
| + | class=" | ||
| + | scope=" | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | </ | ||
| + | |||
| + | **An this is wrong.** The [[http:// | ||
| + | |||
| + | However, I am starting to think that HibernateTemplate doesn' | ||
| + | |||
| + | |||
| + | ==== You can configure also when Hibernate release its session objects ==== | ||
| I've discovered these things that I think they could help in solving the problem: | I've discovered these things that I think they could help in solving the problem: | ||
| Line 276: | Line 286: | ||
| * [[http:// | * [[http:// | ||
| - | Ater trying | + | You can se the parameter |
| - | But I am more and more confident that the problem | + | <code xml> |
| + | <!-- | ||
| + | Possible values for this are: | ||
| + | | ||
| + | the first time it requires it and release it when it's | ||
| + | destroyed | ||
| + | | ||
| + | session | ||
| + | rollback | ||
| + | | ||
| + | connection | ||
| + | BUT it will keep the connection open if the object | ||
| + | | ||
| + | <prop key=" | ||
| - | I've checked | + | </ |
| + | |||
| + | |||
| + | ==== You can configure C3P0 to reopen used connections ==== | ||
| + | |||
| + | For me, this have been the silver bullet that can fix a broken application whihout the need to go back to development to fix the issue. | ||
| + | |||
| + | The configuration parameter [[http:// | ||
| + | |||
| + | - When C3P0 gives a connection to the application, | ||
| + | - When this counter reaches this limit, C3P0 silently replaces this connection and gives another fresh open connection | ||
| + | - This parameter can avoid the problem that I had that C3P0 gave a connection and it went closed because it was retained open for days | ||
| + | |||
| + | However, it is discouraged because it hides problems in the application. But if it can save your day, take it into account. | ||
| + | |||
| + | You have also this parameter: [[http:// | ||
| + | |||
| + | |||
| + | |||
| + | ===== 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 | ||
| + | |||
| + | | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | <!-- | ||
| + | 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 | ||
| + | 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, | ||
| + | replace | ||
| + | of the database may close opened for much time | ||
| + | http:// | ||
| + | --> | ||
| + | < | ||
| + | </ | ||
| - | <code java> | ||
| - | public List find(final String queryString, | ||
| - | return executeWithNativeSession(new HibernateCallback< | ||
| - | public List doInHibernate(Session session) throws HibernateException { | ||
| - | Query queryObject = session.createQuery(queryString); | ||
| - | prepareQuery(queryObject); | ||
| - | if (values != null) { | ||
| - | for (int i = 0; i < values.length; | ||
| - | queryObject.setParameter(i, | ||
| - | } | ||
| - | } | ||
| - | return queryObject.list(); | ||
| - | } | ||
| - | }); | ||
| - | } | ||
| </ | </ | ||
| - | See [[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, | ||
| - | It's more and more clear that something isn't closing the commands. I am starting to think that Hibernate doesn' | + | ===== Resources ===== |
| - | ===== Third approach: paranoia approach ===== | + | http:// |
| - | All these tests have been made on corporate Windows machines. I am starting to think that some kind of security policy is imposed in my user that limits the activity of my windows machine. To be studied... | ||
| ~~DISQUS~~ | ~~DISQUS~~ | ||
java/thelastpacketsuccessfullyreceivedfromserver.1380552408.txt.gz · Last modified: 2022/12/02 21:02 (external edit)
