cancel
Showing results for 
Search instead for 
Did you mean: 

Cron job is creating different JaloSession

Former Member
0 Kudos

Hi Experts,

I am executing a cronjob fron my class, where in cronjob i am setting some values in the session. The problem is when i tried to get the session values it returned null. Then i compared the session ids of both the sessions and got to know that both sessions are different (My class session and cornjob session).

So how can i get the same session which is creating in the cronjon...

Please find the sample code below...

 public void processMail(final JaloSession session, final String dataDir)
 {       
            
     final CronJobModel dynamicCJ = cronJobService.getCronJob("sampleCronJob");

     //Executing the sampleCronJob
     cronJobService.performCronJob(dynamicCJ, true);

     final String testString = (String) session.getAttribute("sessionTest"); // Returning "null"    

     System.out.println("Session ID in processMail() ::::::     " + session.getSessionID());        //Different session id 

 }


 //sampleCronJob 
 public PerformResult perform(final CronJobModel cronJob)
 {

     final Date date = cronJob.getModifiedtime();

     final JaloSession session = serviceUtil.getJaloSession();
     
     session.setAttribute("sessionTest", "Hello Session String");

     System.out.println("Session ID in Perform() ::::::     " + session.getSessionID());
                 
 }

Regards,

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Check this out https://wiki.hybris.com/display/release5/cronjob+-+Technical+Guide

Adjusting the Session for CronJob Execution

Former Member
0 Kudos

Hi

Logically cron jobs are component which execute a particular piece of code in it's own context with a unique job id. What i mean is that when the cron job is fired, the context in which it runs will have a unique session and hence you are getting different session id's. My suggestion is not to use session to store anything for cron job as things will get worst when you move to cluster version. Use an object which you could populate and fed it when the job gets fired.

Regards