The serializable interface and transient keyword in Java table of Contents
- 1. Notserializableexception exception encountered while putting data into memcached
- 2. Troubleshoot and resolve problems
- 3. Summary
1Notserializableexception exception encountered while putting data into memcached
The memcached cache is used in the project to store the customer's organizational structure in order to improve system performance. Before the system is operating normally, recently in order to connect with the portal, updated the organization structure of the jar package (maintained by the company's products department), after the update found that the organizational structure can not be placed in the cache, reported java.io.NotSerializableException exception.
2Troubleshoot and resolve problems
After troubleshooting, found that the Product department modified the entity class Orgnization, added a transaction class member variable, the variable does not implement Serializable interface, and memcached required to store the object to implement serializable interface, So an exception occurred.
The serializable interface declaration was added to the transaction member variable by the way of decompile, modify, compile, and replace, and found in org.apache.tomcat.dbcp.dbcp.poolingdatasource$ Poolguardconnectionwrapper escalation Java.io.NotSerializableException exception, originally, transaction class behind a bunch of database operations related definitions, this can not be modified by third-party classes to solve the problem.
Finally, the problem is solved by adding transient to the Transaction class member variable. With this keyword, you can turn off serialization of member variables. In this way, no matter how many classes behind the serializable interface are not implemented, there is no relationship. And the keyword only works when serialized, without affecting the normal business processing logic.
3Summarize
- Note the difference and effect of implementing the Serializable interface and the transient keyword
- Entity classes are not actually suitable for related code that contains database processing (design issues)
- When slowing down, consider using your own entity classes, and try not to use third-party classes, in order to have an impact when updates change. (Design issues)
Author:galaxy
created:2015-07-01 Wed 11:15
Emacs 24.4.1 (ORG mode 8.2.10)
Validate
Serializable interfaces and transient keywords in Java