views:

56

answers:

1

Hi SO,

I've written a SharePoint 2010 app that uses a TimerJob to trigger processing of some documents in a list. The timer is set to trigger every minute but the the processing may take more than a minute. I'm just wondering if the next trigger of the timer job will be started using a new thread, or will the timer service just wait until the first thread has completed. I.e. I have no idea how Sharepoint manages threads for TimerJobs and I can't really find any relevant information.

This is possibly a problema given that my TimerJob definition has the following:

 public override void Execute(Guid contentDbId)
    {
        try
        {
            SPWebApplication webApplication = this.Parent as SPWebApplication;
            SPContentDatabase contentDb = webApplication.ContentDatabases[contentDbId];
            using (SPSite site = contentDb.Sites[0])
            {
                using (SPWeb web = site.RootWeb)
                {                       
                    PRManager.TriggerProcessing(web);    // ?                   
                }
            }
        }                      
        catch (Exception)
        { 
        }
    }
}

The PRManager.TriggerProcessing() is a static method, obviously, and while it does contain mechanisms to limit only one thread at a time entering the method body, I'm just wondering IF SharePoint does create multiple threads in the event that those at-minute-interval calls to execute overlap.

Thanks in advance.

+2  A: 

Well, it is not so much a "thread" thing as much as it is a "job" thing.

SharePoint stores all jobs in a database table and it uses this table to track what is running and where it is running. It has a built in synchronization engine that is responsible for making sure the jobs execute as the job instructions say.

For example take the deployment ask which is nothing more than a job. The deployment task only allows One job to run for a given solution at a time. It makes sure that all of the tasks finish on each server in the farm before the overall job is reported as done.

So the answer will depend on how your job configuration properties are set. There is a property that tells SharePoint to only allow one job to run at a time. So if the job is currently executing another instance will not be started.

JD
Cheers man. When you say "Job configuration properties", do you mean some "one job at a time" type property of the actual SPJobDefinition I've created?