1

I am writing a console application that will do two tasks.
The app will be run by a Windows scheduler once a day during off-peak hours, when it does run it will do the following:

  • Scan 5-6 folders with several hundred files, update a SQL table with the file names
  • This app will be referenced by two other applications, these applications will utilize a public method to write exceptions to a SQL table. The exceptions would more of business rule exceptions.

There is a possibility that the app will be called by the scheduler to do its assigned task and also by the other applications at the same time. How would I design the app to ensure that there are no conflicts. I am thinking along the lines of multi threading, parallel tasks?

1
  • Which language are you using? Please put the appropriate tag. Commented Mar 29, 2012 at 9:13

1 Answer 1

2

You do not really need to do anything. The OS handles all the parallelism for you in this situation. The task scheduler starts one process. Those other apps that use yours are running in separate processes. You can run all the processing on a single thread and both tasks can still proceed in parallel.

The only thing you need to be careful about is shared resources. For example, if you’re writing to a hard-coded log file while doing this, one of the tasks will either fail, or will have to wait for the log file to become writable.

Unless you’re doing something silly, the SQL access should be no problem either; just make sure you run all the queries that pertain to a task in a transaction, leaving the database in a consistent state at the end of the transaction.

One potential source of problem is the pretend-serializable transactions, as I like to call them. In MSSQL they are called SNAPSHOT transactions. To be absolutely fully safe, make sure you use serializable transactions and be ready to retry the whole thing if the commit fails due to a conflict.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.