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:25] – [My architecture] rlunaro | java:thelastpacketsuccessfullyreceivedfromserver [2022/12/02 21:02] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 13: | Line 13: | ||
| * Mysql worked perfectly | * Mysql worked perfectly | ||
| * There wasn't a network error | * There wasn't a network error | ||
| - | * So... what the problem | + | * So... were the problem |
| ==== My architecture ==== | ==== My architecture ==== | ||
| Line 275: | 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 322: | 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.1380698739.txt.gz · Last modified: 2022/12/02 21:02 (external edit)
