根据这个功能,写了一个.net控制台程序来测试,测试程序没有使用任何数据访问框架,直接使用ADO.NET,下面是多线程测试的代码,其它代码略:
- public static void Test2(string connName1,string connName2)
- {
- System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
- watch.Start();
- string allJjdmList = "";
- string connString = getConnectionString();
- //SqlConnection conn = new SqlConnection(connString);
- //conn.Open();
-
- string sql = "select jjdm from [FundYield] group by jjdm order by jjdm asc";
- DataSet ds = getData(connString, sql);
- int allCount = ds.Tables[0].Rows.Count;
- int p = (int)(allCount * 0.5);
-
- System.Threading.Thread t1=new System.Threading.Thread (new System.Threading.ParameterizedThreadStart (tp1=>
- {
- for (int i = 0; i < p; i++)
- {
- string jjdm = ds.Tables[0].Rows[i][0].ToString();
-
- object result = getSclar(ConfigurationManager.ConnectionStrings[connName1].ConnectionString,
- string.Format("select MAX(fsrq) from [FundYield] where jjdm='{0}'", jjdm));
- if (result != DBNull.Value)
- {
- DateTime dt = Convert.ToDateTime(result);
- //Console.WriteLine("Thread 2 No {0} ,jjdm[{1}] last FSRQ is:{2}", i, jjdm, dt);
- }
-
- allJjdmList = allJjdmList + "," + jjdm;
- }
-
- Console.WriteLine("Tread 1 used all time is(ms):{0}", watch.ElapsedMilliseconds);
- }
- ));
-
- System.Threading.Thread t2 = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(tp2 =>
- {
- for (int i = p; i < allCount; i++)
- {
- string jjdm = ds.Tables[0].Rows[i][0].ToString();
- //这里不论使用default还是express,区别不大
- object result = getSclar(ConfigurationManager.ConnectionStrings[connName2].ConnectionString,
- string.Format("select MAX(fsrq) from [FundYield] where jjdm='{0}'", jjdm));
- if (result != DBNull.Value)
- {
- DateTime dt = Convert.ToDateTime(result);
- //Console.WriteLine("Thread 2 No {0} ,jjdm[{1}] last FSRQ is:{2}", i, jjdm, dt);
- }
-
- allJjdmList = allJjdmList + "," + jjdm;
- }
-
- Console.WriteLine("Tread 2 used all time is(ms):{0}", watch.ElapsedMilliseconds);
- }
- ));
-
- t1.Start();
- t2.Start();
- t1.Join();
- t2.Join();
-
- Console.WriteLine("====All thread completed!========");
-
- }
|