Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Issue of context switch between two threads  RSS feed

 
Deepak Amar
Greenhorn
Posts: 11
1
  • Mark post as helpful
  • send pies
  • 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)
 
avi sinha
Ranch Hand
Posts: 453
Google Web Toolkit Hibernate Java
  • Mark post as helpful
  • send pies
  • 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

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!