• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Issue of context switch between two threads

 
Greenhorn
Posts: 22
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am Using Quarts Scheduler for job scheduling. I have various jobs which gets medical report of different users daily and send that report to individual user. Each job has a specific user associated with it.
Before each job starts executing its business logic the JobListener implementation class creates an instance of the class UserJobExecution. (Code snippet given below)


Both the above classes has a User object that has two fields username and password.
Every job makes a call to a common webservice by calling its executeMethod with its own user name and password to get medical report associated to a particular user.
The webservice takes time to process a report. So first a job requests for a report and gets a report Id and then the job continuously calls the webservice for retrieving that report every 15 secs till webservice processes the report and the job gets the report.

The issue i am facing is that if there are multiple jobs triggered at the same time then it messes up the username and password.(The above getCurrent() method is called to get the currently executing job)
 
Ranch Hand
Posts: 453
Google Web Toolkit Hibernate Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Deepak,

The UserJobExecution class looks good except some encapsulation issues. Please find my suggestions below to narrow down the area.

1. Use generics for ThreadLocal return type.It will make it more readable. Where are you setting it?
2. Don't swallow the exception. Do you want to hit the service even when the user object is not available?
3. Use proper encapsulation in both the classes. you will never know who is changing the variables from outside.
4. Make the User class immutable to protect it. I don't think it should be mutable.
4. Use logs/assert in the execute method to verify whether everything is correct there. If everything looks fine, i guess the problem is inside the executeService or with the client.

Thanks
Avi

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic