title: java.lang.IllegalArgumentException: setAttribute: Non-serializable attribute
body: <p>I have inherited some code and am getting an error when I try to run it. The error is below:</p>
  
  <pre><code>10:08:32,093 ERROR [MyServlet]:260 - Servlet.service() for servlet MyServlet threw exception
  java.lang.IllegalArgumentException: setAttribute: Non-serializable attribute
  at org.apache.catalina.session.StandardSession.setAttribute(StandardSession.java:1270)
  at org.apache.catalina.session.StandardSession.setAttribute(StandardSession.java:1248)
  at org.apache.catalina.session.StandardSessionFacade.setAttribute(StandardSessionFacade.java:130)
  at uk.co.my.servlet.MyServlet.doPost(MyServlet.java:121)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
  at com.my.ddi.security.SecurityContextServletFilter.doFilter(SecurityContextServletFilter.java:55)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
  at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
  at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:835)
  at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:640)
  at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1286)
  at java.lang.Thread.run(Unknown Source)
  </code></pre>
  
  <p>I imagine that the main problem is where it is hitting my code <em>at uk.co.my.servlet.MyServlet.doPost(MyServlet.java:172)</em>. Line 121 of  MyServlet is 
  session.setAttribute("LISTENER", myListener);</p>
  
  <p>This myListener object is from the following class:</p>
  
  <pre><code>public class myListener {
      static Log log = LogFactory.getLog(TerminationListener.class.getName());
      private boolean shouldCancel = false;
  </code></pre>
  
  <p>How would I go about getting rid of this error? Would I need to use the transient keyword?</p>