Sophie

Sophie

distrib > Fedora > 14 > i386 > by-pkgid > 864d1c3c3cd8df4e3a2692faf8776e05 > files > 225

db4o-doc-7.4-2.fc13.i686.rpm

<html>
  <head>
    <META http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Pessimistic Locking</title>
    <link rel="stylesheet" type="text/css" href="../../../style.css">
  </head>
  <body>
    <div class="CommonContent">
      <div class="CommonContentArea">
        <h1>Pessimistic Locking</h1><script>
//We attach this function to a browser object as a variable so that if multiple of these blocks are
//present on the same page, then they will simply over-write eachother with the same function instead
//of generating a naming collision.
window.WikiCodeFormattingCopyToClipboard = function copyToClipboard(sID){
	var sContent = document.getElementById(sID).innerText;
	if( window.clipboardData && clipboardData.setData )
	{
		clipboardData.setData("Text", sContent);
	}
	else
	{
		alert("You must enable javascript access to your clipboard for this feature to work. Please referr to your browser documentation or Google search for instructions.");
	}
}
</script><p>Pessimistic locking is an approach when an entity is locked in the
database for the entire time that it is in application memory. This means that
an object should be locked as soon as it is retrieved from the database and
released after commit.</p>



<span name="cs_wiki_filter" csw_filters="cs"><div class="FormattedSourceCode"><div class="fscHeader"><span class="fscFileName">PessimisticThread.cs: <span class="fscMemberName">run</span></span></div><div class="fscCode"><pre ID="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--><span style="color: #008080;">01</span><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/None.gif" align="top"/><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> Run()
</span><span style="color: #008080;">02</span><span style="color: #000000;"><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_26_980_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_26_980_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_26_980_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_26_980_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_26_980_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_26_980_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_26_980_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_26_980_Open_Text').style.display='inline';"/>        </span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_26_980_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_26_980_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">03</span><span style="color: #000000;"><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_44_923_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_44_923_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_44_923_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_44_923_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_44_923_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_44_923_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_44_923_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_44_923_Open_Text').style.display='inline';"/>            </span><span style="color: #0000FF;">try</span><span style="color: #000000;"> </span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_44_923_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_44_923_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">04</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        IObjectSet result </span><span style="color: #000000;">=</span><span style="color: #000000;"> _container.Get(</span><span style="color: #0000FF;">typeof</span><span style="color: #000000;">(Pilot));
</span><span style="color: #008080;">05</span><span style="color: #000000;"><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_133_916_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_133_916_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_133_916_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_133_916_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_133_916_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_133_916_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_133_916_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_133_916_Open_Text').style.display='inline';"/>        </span><span style="color: #0000FF;">while</span><span style="color: #000000;"> (result.HasNext())</span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_133_916_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_133_916_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">06</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>          Pilot pilot </span><span style="color: #000000;">=</span><span style="color: #000000;"> (Pilot)result.Next();
</span><span style="color: #008080;">07</span><span style="color: #000000;"><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_185_278_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_185_278_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_185_278_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_185_278_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_185_278_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_185_278_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_185_278_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_185_278_Open_Text').style.display='inline';"/>          </span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_185_278_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">/**/</span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_185_278_Open_Text"><span style="color: #008000;">/*</span><span style="color: #008000;"> with pessimistic approach the object is locked as soon 
</span><span style="color: #008080;">08</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>           * as we get it 
</span><span style="color: #008080;">09</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"/>           </span><span style="color: #008000;">*/</span></span><span style="color: #000000;"> 
</span><span style="color: #008080;">10</span><span style="color: #000000;"><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_364_432_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_364_432_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_364_432_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_364_432_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_364_432_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_364_432_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_364_432_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_364_432_Open_Text').style.display='inline';"/>          </span><span style="color: #0000FF;">if</span><span style="color: #000000;"> (</span><span style="color: #000000;">!</span><span style="color: #000000;">_container.Ext().SetSemaphore(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">LOCK_</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">+</span><span style="color: #000000;">_container.Ext().GetID(pilot), </span><span style="color: #800080;">0</span><span style="color: #000000;">))</span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_364_432_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_364_432_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">11</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            Console.WriteLine(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Error. The object is locked</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">);
</span><span style="color: #008080;">12</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"/>          }</span></span><span style="color: #000000;">
</span><span style="color: #008080;">13</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>          
</span><span style="color: #008080;">14</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>          Console.WriteLine(Name </span><span style="color: #000000;">+</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Updating pilot: </span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> pilot);
</span><span style="color: #008080;">15</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>              pilot.AddPoints(</span><span style="color: #800080;">1</span><span style="color: #000000;">);
</span><span style="color: #008080;">16</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>              _container.Set(pilot);
</span><span style="color: #008080;">17</span><span style="color: #000000;"><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_584_687_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_584_687_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_584_687_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_584_687_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_584_687_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_584_687_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_584_687_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_584_687_Open_Text').style.display='inline';"/>              </span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_584_687_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">/**/</span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_584_687_Open_Text"><span style="color: #008000;">/*</span><span style="color: #008000;"> The changes should be committed to be 
</span><span style="color: #008080;">18</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>               * visible to the other clients
</span><span style="color: #008080;">19</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"/>               </span><span style="color: #008000;">*/</span></span><span style="color: #000000;">
</span><span style="color: #008080;">20</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>              _container.Commit();
</span><span style="color: #008080;">21</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>              _container.Ext().ReleaseSemaphore(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">LOCK_</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">+</span><span style="color: #000000;">_container.Ext().GetID(pilot));
</span><span style="color: #008080;">22</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>              Console.WriteLine(Name </span><span style="color: #000000;">+</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Updated pilot: </span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> pilot);
</span><span style="color: #008080;">23</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>              Console.WriteLine();
</span><span style="color: #008080;">24</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"/>        }</span></span><span style="color: #000000;">
</span><span style="color: #008080;">25</span><span style="color: #000000;"><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_932_966_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_932_966_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_932_966_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_932_966_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_932_966_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_932_966_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_932_966_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_932_966_Open_Text').style.display='inline';"/>      }</span></span><span style="color: #000000;"> </span><span style="color: #0000FF;">finally</span><span style="color: #000000;"> </span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_932_966_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyCS.ZipsPessimisticThread.Cs_PessimisticThread.Cs_Run_307_52_932_966_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">26</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>        _container.Close();
</span><span style="color: #008080;">27</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"/>      }</span></span><span style="color: #000000;">
</span><span style="color: #008080;">28</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>   
</span><span style="color: #008080;">29</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockEnd.gif" align="top"/>        }</span></span></div></pre></div></div>&nbsp;</p></span><span name="cs_wiki_filter" csw_filters="vb">
<div class="FormattedSourceCode"><div class="fscHeader"><span class="fscFileName">PessimisticThread.vb: <span class="fscMemberName">run</span></span></div><div class="fscCode"><pre ID="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsPessimisticThread.Vb_PessimisticThread.Vb_Run_423_52"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--><span style="color: #008080;">01</span><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsPessimisticThread.Vb_PessimisticThread.Vb_Run_423_52_7_1196_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsPessimisticThread.Vb_PessimisticThread.Vb_Run_423_52_7_1196_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsPessimisticThread.Vb_PessimisticThread.Vb_Run_423_52_7_1196_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsPessimisticThread.Vb_PessimisticThread.Vb_Run_423_52_7_1196_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsPessimisticThread.Vb_PessimisticThread.Vb_Run_423_52_7_1196_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsPessimisticThread.Vb_PessimisticThread.Vb_Run_423_52_7_1196_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsPessimisticThread.Vb_PessimisticThread.Vb_Run_423_52_7_1196_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsPessimisticThread.Vb_PessimisticThread.Vb_Run_423_52_7_1196_Open_Text').style.display='inline';"/><span style="color: #0000FF;">Public</span><span style="color: #000000;"> </span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsPessimisticThread.Vb_PessimisticThread.Vb_Run_423_52_7_1196_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">Sub Run()</span><span id="ResourcesReferenceClient-ServerConcurrency_ControlConcurrencyVB.ZipsPessimisticThread.Vb_PessimisticThread.Vb_Run_423_52_7_1196_Open_Text"><span style="color: #0000FF;">Sub</span><span style="color: #000000;"> Run()
</span><span style="color: #008080;">02</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            </span><span style="color: #0000FF;">Try</span><span style="color: #000000;">
</span><span style="color: #008080;">03</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                </span><span style="color: #0000FF;">Dim</span><span style="color: #000000;"> result </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> IObjectSet </span><span style="color: #000000;">=</span><span style="color: #000000;"> _container.Get(</span><span style="color: #0000FF;">GetType</span><span style="color: #000000;">(Pilot))
</span><span style="color: #008080;">04</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                </span><span style="color: #0000FF;">While</span><span style="color: #000000;"> result.HasNext
</span><span style="color: #008080;">05</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                    </span><span style="color: #0000FF;">Dim</span><span style="color: #000000;"> pilot </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> Pilot </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">CType</span><span style="color: #000000;">(result.Next, Pilot)
</span><span style="color: #008080;">06</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                    </span><span style="color: #008000;">'</span><span style="color: #008000;"> with pessimistic approach the object is locked as soon </span><span style="color: #008000;">
</span><span style="color: #008080;">07</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/></span><span style="color: #000000;">                    </span><span style="color: #008000;">'</span><span style="color: #008000;"> as we get it </span><span style="color: #008000;">
</span><span style="color: #008080;">08</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/></span><span style="color: #000000;">                    </span><span style="color: #0000FF;">If</span><span style="color: #000000;"> </span><span style="color: #0000FF;">Not</span><span style="color: #000000;"> _container.Ext.SetSemaphore(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">LOCK_</span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> _container.Ext.GetID(pilot).ToString(), </span><span style="color: #800080;">0</span><span style="color: #000000;">) </span><span style="color: #0000FF;">Then</span><span style="color: #000000;">
</span><span style="color: #008080;">09</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                        Console.WriteLine(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Error. The object is locked</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">)
</span><span style="color: #008080;">10</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                    </span><span style="color: #0000FF;">End</span><span style="color: #000000;"> </span><span style="color: #0000FF;">If</span><span style="color: #000000;">
</span><span style="color: #008080;">11</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                    Console.WriteLine(Name </span><span style="color: #000000;">+</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Updating pilot: </span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> pilot.ToString())
</span><span style="color: #008080;">12</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                    pilot.AddPoints(</span><span style="color: #800080;">1</span><span style="color: #000000;">)
</span><span style="color: #008080;">13</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                    _container.Set(pilot)
</span><span style="color: #008080;">14</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                    </span><span style="color: #008000;">'</span><span style="color: #008000;"> The changes should be committed to be </span><span style="color: #008000;">
</span><span style="color: #008080;">15</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/></span><span style="color: #000000;">                    </span><span style="color: #008000;">'</span><span style="color: #008000;"> visible to the other clients</span><span style="color: #008000;">
</span><span style="color: #008080;">16</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/></span><span style="color: #000000;">                    _container.Commit()
</span><span style="color: #008080;">17</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                    _container.Ext.ReleaseSemaphore(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">LOCK_</span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> _container.Ext.GetID(pilot).ToString())
</span><span style="color: #008080;">18</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                    Console.WriteLine(Name </span><span style="color: #000000;">+</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Updated pilot: </span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> pilot.ToString())
</span><span style="color: #008080;">19</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                    Console.WriteLine()
</span><span style="color: #008080;">20</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                </span><span style="color: #0000FF;">End</span><span style="color: #000000;"> </span><span style="color: #0000FF;">While</span><span style="color: #000000;">
</span><span style="color: #008080;">21</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            </span><span style="color: #0000FF;">Finally</span><span style="color: #000000;">
</span><span style="color: #008080;">22</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                _container.Close()
</span><span style="color: #008080;">23</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            </span><span style="color: #0000FF;">End</span><span style="color: #000000;"> </span><span style="color: #0000FF;">Try</span><span style="color: #000000;">
</span><span style="color: #008080;">24</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockEnd.gif" align="top"/>        </span><span style="color: #0000FF;">End Sub</span></span></div></pre></div></div>&nbsp;</p>
</span>
<p>As you see this approach is considerably easier to implement.
Another advantage is that it guarantees that your changes to the database are
made consistently and safely.</p>

<p>The main disadvantage is the lack of scalability. Time
waiting for the lock to be released can become unacceptable for a system with
many users or long transactions. This limits the practical implementations of
pessimistic locking.</p>

<p>You may want to select pessimistic locking
in cases when the cost of loosing the transaction results due to a collision is
too high.</p>



</div>
    </div>
    <div id="footer">
					This revision (2) was last Modified 2006-12-18T14:50:20 by Tetyana.
				</div>
  </body>
</html>