on 04-21-2015 7:53 AM
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,
Check this out https://wiki.hybris.com/display/release5/cronjob+-+Technical+Guide
Adjusting the Session for CronJob Execution
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
5 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.