public static void Target33(object obj) { TableObj <XHHoldMemoryTable> tableObj = obj as TableObj <XHHoldMemoryTable>; if (tableObj == null) { return; } //ShowMessage(0, tableObj.val, 0); int val = tableObj.val; var table = tableObj.Table;//.AddDelta(val, val, val, val); var data = table.Data; XH_AccountHoldTableInfo_Delta delta = new XH_AccountHoldTableInfo_Delta(); delta.AccountHoldLogoId = data.AccountHoldLogoId; delta.AvailableAmountDelta = -val; delta.Data = data; bool isSuccess = false; bool isCapitalSuccess = false; Database database = DatabaseFactory.CreateDatabase(); using (DbConnection connection = database.CreateConnection()) { connection.Open(); DbTransaction transaction = connection.BeginTransaction(); try { isCapitalSuccess = table.CheckAndAddDelta(func2, delta, database, transaction); if (!isCapitalSuccess) { Console.WriteLine("----------holdfailure"); Console.WriteLine("holdfailure data=" + table.Data.AvailableAmount); throw new Exception(); } transaction.Commit(); isSuccess = true; } catch (Exception) { transaction.Rollback(); isSuccess = false; Console.WriteLine("事务失败!"); } } if (!isSuccess) { if (isCapitalSuccess) { table.RollBackMemory(delta); Console.WriteLine("rollback data=" + table.Data.AvailableAmount); } } }
public static void Target2(object obj) { TableObj <XHCapitalMemoryTable> tableObj = obj as TableObj <XHCapitalMemoryTable>; if (tableObj == null) { return; } //ShowMessage(0, tableObj.val, 0); int val = tableObj.val; var table = tableObj.Table;//.AddDelta(val, val, val, val); XH_CapitalAccountTable_DeltaInfo delta = new XH_CapitalAccountTable_DeltaInfo(); delta.AvailableCapitalDelta = -val; if (table.Data.AvailableCapital - val > 0) { table.AddDelta(delta); } else { Console.WriteLine("-"); } }
public static void Target1(object obj) { TableObj <XHCapitalMemoryTable> tableObj = obj as TableObj <XHCapitalMemoryTable>; if (tableObj == null) { return; } //ShowMessage(0, tableObj.val, 0); int val = tableObj.val; //tableObj.Table.AddDelta(val, val, val, val); }
public static void TestHold3() { Console.WriteLine("开始TestHold3"); MemoryDataManager.Start(); var table1 = MemoryDataManager.XHHoldMemoryList.GetByAccountHoldLogoId(1); Thread t = new Thread(RunHoldTableThread); TableObj <XHHoldMemoryTable> obj1 = new TableObj <XHHoldMemoryTable>(); obj1.Table = table1; t.Start(obj1); ExitConsole(); MemoryDataManager.End(); }
/// <summary> /// 一个持仓id多线程插入(带检查) /// </summary> public static void Test222() { MemoryDataManager.Start(); XHHoldMemoryTable table = MemoryDataManager.XHHoldMemoryList.GetByAccountHoldLogoId(1375); for (int i = 0; i < 5; i++) { Thread t = new Thread(Target33); TableObj <XHHoldMemoryTable> obj = new TableObj <XHHoldMemoryTable>(); obj.Table = table; obj.val = 200; t.Start(obj); } ExitConsole(); MemoryDataManager.End(); }
/// <summary> /// 一个资金id多线程插入(带检查) /// </summary> public static void Test22() { MemoryDataManager.Start(); var table = MemoryDataManager.XHCapitalMemoryList.GetByCapitalAccountLogo(1756); for (int i = 0; i < 2; i++) { Thread t = new Thread(Target3); TableObj <XHCapitalMemoryTable> obj = new TableObj <XHCapitalMemoryTable>(); obj.Table = table; obj.val = i + 1; t.Start(obj); } ExitConsole(); MemoryDataManager.End(); }
private static void DoHoldAction(object obj) { TableObj <XHHoldMemoryTable> tableObj = obj as TableObj <XHHoldMemoryTable>; var table1 = tableObj.Table; int i = tableObj.val; table1.ReadAndWrite(hold => { hold.AvailableAmount += i; hold.BreakevenPrice += i; hold.CostPrice += i; hold.FreezeAmount += i; hold.HoldAveragePrice += i; Console.WriteLine(hold.AccountHoldLogoId + "Write" + i); return(hold); }); }
private static void RunTableThread(object tableObj) { XHCapitalMemoryTable table = tableObj as XHCapitalMemoryTable; if (table == null) { return; } for (int i = 0; i < 1000; i++) { Thread t = new Thread(Target1); TableObj <XHCapitalMemoryTable> obj = new TableObj <XHCapitalMemoryTable>(); obj.Table = table; obj.val = i + 1; t.Start(obj); } Console.WriteLine("插入结束!"); }
private static void RunHoldTableThread(object tobj) { var tableObj = tobj as TableObj <XHHoldMemoryTable>; var table = tableObj.Table; if (table == null) { return; } for (int i = 0; i < 1000; i++) { Thread t = new Thread(DoHoldAction); TableObj <XHHoldMemoryTable> obj = new TableObj <XHHoldMemoryTable>(); obj.Table = table; obj.val = i + 1; t.Start(obj); var data = table.Data; Console.WriteLine(data.AccountHoldLogoId + "Read" + +(i + 1) + ":" + data.AvailableAmount); } Console.WriteLine("插入结束!"); }