title: Drools stateless vs stateful session
body: <p>Need some help !!
  I don't have a clear understanding on stateful and stateless sessions in Drools.
  I am trying to understand this , so attempted an example .</p>
  
  <p>I have tested the below drl with stateful and stateless sessions on drools6.5 version and it resulted with same output in both the cases.From what I understood with stateless session it should execute only first rule and second rule should not be activated when the Application object is modified in the first rule("Is of valid age").  Attaching the source code. Appreciate any help on this.</p>
  
  <pre><code>package com.company.license
  
  import com.sample.dto.Applicant;
  import com.sample.dto.Application;
  import java.util.Date;
  
  
  rule "Is of valid age"
  no-loop
      when 
          Applicant( age &lt; 18 )
          $a : Application()
      then
          $a.setValid( false );
          modify($a){setDateApplied(new Date())};
          System.out.println("from rule Is of Valid age --  " +$a.isValid() );
      end
  
  rule "Application was made this year"
      when 
          $a : Application( dateApplied &gt; "01-jan-2009" )
      then 
      $a.setValid( true);
      System.out.println("from rule made this year --  " +$a.isValid() );
  end
  
  
  package com.sample.dto;
  
  import java.util.Date;
  
  public class Application {
      public Date dateApplied;
      public boolean valid;
  
      // getter and setter methods here
      public Date getDateApplied() {
          return dateApplied;
      }
      public void setDateApplied(Date dateApplied) {
          this.dateApplied = dateApplied;
      }
      public boolean isValid() {
          return valid;
      }
      public void setValid(boolean valid) {
          this.valid = valid;
      }
  }
  
  
  package com.sample.dto;
  public class Applicant {
      public String name;
      public int age;
  
      public Applicant(String name,int age){
          this.name =  name;
          this.age=age;
      }
  
  
      public String getName() {
          return name;
      }
  
  
      public void setName(String name) {
          this.name = name;
      }
  
  
      public int getAge() {
          return age;
      }
  
  
      public void setAge(int age) {
          this.age = age;
      }
  }
  
  package com.sample;
  
  import java.util.Arrays;
  
  import org.kie.api.KieServices;
  import org.kie.api.runtime.KieContainer;
  import org.kie.api.runtime.KieSession;
  import org.kie.api.runtime.StatelessKieSession;
  
  import com.sample.dto.Applicant;
  import com.sample.dto.Application;
  
  /**
   * This is a sample class to launch a rule.
   */
  public class LicenseTestStateful {
  
      public static final void main(String[] args) {
          try {
              // load up the knowledge base
              KieServices ks = KieServices.Factory.get();
              KieContainer kContainer = ks.getKieClasspathContainer();
              KieSession ksession = kContainer.newKieSession("ksession-rules");
              Applicant applicant = new Applicant( "Mr John Smith", 16);
              Application application = new Application();
              ksession.execute(ks.getCommands().newInsertElements(Arrays.asList(new Object[]{application,applicant})));
              ksession.fireAllRules();
              ksession.dispose();
  
          } catch (Throwable t) {
              t.printStackTrace();
          }
      }
  }
  
  
  package com.sample;
  
  import java.util.Arrays;
  
  import org.kie.api.KieServices;
  import org.kie.api.runtime.KieContainer;
  import org.kie.api.runtime.KieSession;
  import org.kie.api.runtime.StatelessKieSession;
  
  import com.sample.dto.Applicant;
  import com.sample.dto.Application;
  
  /**
   * This is a sample class to launch a rule.
   */
  public class LicenseTestStateless {
  
      public static final void main(String[] args) {
          try {
              // load up the knowledge base
              KieServices ks = KieServices.Factory.get();
              KieContainer kContainer = ks.getKieClasspathContainer();
              StatelessKieSession ksession = kContainer.newStatelessKieSession();
              Applicant applicant = new Applicant( "Mr John Smith", 16);
              Application application = new Application();
              ksession.execute(ks.getCommands().newInsertElements(Arrays.asList(new Object[]{application,applicant})));       
          } catch (Throwable t) {
              t.printStackTrace();
          }
      }
  }
  
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule"&gt;
      &lt;kbase name="rules" packages="rules"&gt;
          &lt;ksession name="ksession-rules"/&gt;
          &lt;ksession name="statelesssession" type="stateless" default="true"/&gt;
      &lt;/kbase&gt;
      &lt;kbase name="dtables" packages="dtables"&gt;
          &lt;ksession name="ksession-dtables"/&gt;
      &lt;/kbase&gt;
      &lt;kbase name="process" packages="process"&gt;
          &lt;ksession name="ksession-process"/&gt;
      &lt;/kbase&gt;
  &lt;/kmodule&gt;
  
  
  Output:
  from rule Is of Valid age --  false
  from rule made this year --  true
  </code></pre>