我正在研究一项战略,利用多读(可能是偶然的代表们)开展同步行动。 我是新到的,这样一来将首先概述我的设想。 如今,根据所提供的参数对一组数据(组合)进行了同步操作。 下面(简称代码)实施:
public DataSet DoTests(int fundId, DateTime portfolioDate)
{
// Get test results for the portfolio
// Call the database adapter method, which in turn is a stored procedure,
// which in turns runs a series of "rule" stored procs and fills a local temp table and returns it back.
DataSet resultsDataSet = GetTestResults(fundId, portfolioDate);
try
{
// Do some local processing on the results
DoSomeProcessing(resultsDataSet);
// Save the results in Test, TestResults and TestAllocations tables in a transaction.
// Sets a global transaction which is provided to all the adapter methods called below
// It is defined in the Base class
StartTransaction("TestTransaction");
// Save Test and get a testId
int testId = UpdateTest(resultsDataSet); // Adapter method, uses the same transaction
// Update testId in the other tables in the dataset
UpdateTestId(resultsDataSet, testId);
// Update TestResults
UpdateTestResults(resultsDataSet); // Adapter method, uses the same transaction
// Update TestAllocations
UpdateTestAllocations(resultsDataSet); // Adapter method, uses the same transaction
// It is defined in the base class
CommitTransaction("TestTransaction");
}
catch
{
RollbackTransaction("TestTransaction");
}
return resultsDataSet;
}
现在,需要的是提供多套数据。 一种办法是将上述<代码>()方法称作一种格式并获取数据。 我倾向于同时这样做。 但有一些渔获:
StartTransaction()
method creates a connection (and transaction) every time it is called.- All the underlying database tables, procedures are the same for each call of
DoTests().
(obviously).
因此,我的问题是:
- Will using multithreading anyway improve performance?
- What are the chances of deadlock especially when new TestId s are being created and the Tests, TestResults and TestAllocations are being saved? How can these deadlocked be handled?
- Is there any other more efficient way of doing the above operation apart from looping over the
DoTests()
method repeatedly?