SERIALIZABLE interfaces and transient keywords in Java

Source: Internet
Author: User


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
    1. Note the difference and effect of implementing the Serializable interface and the transient keyword
    2. Entity classes are not actually suitable for related code that contains database processing (design issues)
    3. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.