简体   繁体   中英

Non-serializable field in serializable class (transient keyword)

I have a serializable class that extends Servlet

public class FileDownload extends HttpServlet{
  @SuppressWarnings("compatibility:6754389671327954013")
  private static final long serialVersionUID = 1L;
  private ResultSet rset;
  ......
}

My Question is:

Is the rset object automatically converted as transient at compile- or run-time? or do I have to mark it explicitly as transient ? (That is a warning brought up from my IDE JDeveloper).

No, the field is not neglected by serialization - you'll get a java.io.NotSerializableException if you try to serialize an instance of FileDownload . Mark it transient . Btw, what is a ResultSet doing as a field in a Servlet ? This is not thread-safe. ResultSets should be local variables only, in any context.

You have to call transient your own.But you cannot serialize an object unless it implements Serializable interface.ResultSet is such kind of object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM