Update reference documentation generation tools to get source highlighting [SPRNET-1045]
This commit is contained in:
@@ -1,11 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<chapter id="threading">
|
||||
<!--
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
-->
|
||||
<chapter xml:id="threading" xmlns="http://docbook.org/ns/docbook" version="5">
|
||||
<title>Threading and Concurrency Support</title>
|
||||
|
||||
<sect1 id="threading-introduction">
|
||||
<sect1 xml:id="threading-introduction">
|
||||
<title>Introduction</title>
|
||||
|
||||
<para>The purpose of the <classname>Spring.Threading</classname> namespace
|
||||
<para>The purpose of the <literal>Spring.Threading</literal> namespace
|
||||
is to provide a place to keep useful concurrency abstractions that augment
|
||||
those in the BCL. Since Doug Lea has provided a wealth of mature public
|
||||
domain concurrency abstractions in his Java based
|
||||
@@ -26,8 +43,8 @@
|
||||
to use for storing objects in thread local storage. If you are in web
|
||||
applications a single Request may be executed on different threads. As
|
||||
such, the location to store thread local objects is in
|
||||
<classname>HttpContext.Current</classname>. For other environments
|
||||
<classname>System.Runtime.Remoting.Messaging.CallContext</classname> is
|
||||
<literal>HttpContext.Current</literal>. For other environments
|
||||
<literal>System.Runtime.Remoting.Messaging.CallContext</literal> is
|
||||
used. For more background information on the motivation behind these
|
||||
choices, say as compared to the attribute [ThreadStatic] refer to
|
||||
"Piers7"'s <ulink
|
||||
@@ -40,7 +57,7 @@
|
||||
implementation of IThreadStorage makes it easier to have more portability
|
||||
across runtime environments.</para>
|
||||
|
||||
<para>The API is quite simple and shown below<programlisting>public interface IThreadStorage
|
||||
<para>The API is quite simple and shown below<programlisting language="csharp">public interface IThreadStorage
|
||||
{
|
||||
object GetData(string name)
|
||||
|
||||
@@ -58,27 +75,27 @@
|
||||
the method <methodname>FreeNamedDataSlot</methodname>.</para>
|
||||
|
||||
<para>In <literal>Spring.Core</literal> is the implementation,
|
||||
<classname>CallContextStorage</classname>, that directly uses
|
||||
<classname>CallContext</classname> and also the implementation
|
||||
<classname>LogicalThreadContext</classname> which by default uses
|
||||
<classname>CallContextStorage</classname> but can be configured via the
|
||||
<literal>CallContextStorage</literal>, that directly uses
|
||||
<literal>CallContext</literal> and also the implementation
|
||||
<literal>LogicalThreadContext</literal> which by default uses
|
||||
<literal>CallContextStorage</literal> but can be configured via the
|
||||
static method <methodname>SetStorage(IThreadStorage)</methodname>. The
|
||||
methods on CallContextStorage and LogicalThreadContext are static.</para>
|
||||
|
||||
<para>In <literal>Spring.Web</literal> is the implementation
|
||||
<classname>HttpContextStorage</classname> which uses the
|
||||
<classname>HttpContext</classname> to store thread local data and
|
||||
<classname>HybridContextStorage</classname> that uses
|
||||
<classname>HttpContext</classname> if within a web environment, i.e.
|
||||
<literal>HttpContextStorage</literal> which uses the
|
||||
<literal>HttpContext</literal> to store thread local data and
|
||||
<literal>HybridContextStorage</literal> that uses
|
||||
<literal>HttpContext</literal> if within a web environment, i.e.
|
||||
<literal>HttpContext.Current != null</literal>, and
|
||||
<classname>CallContext</classname> otherwise.</para>
|
||||
<literal>CallContext</literal> otherwise.</para>
|
||||
|
||||
<para>Spring internally uses <classname>LogicalThreadContext</classname>
|
||||
<para>Spring internally uses <literal>LogicalThreadContext</literal>
|
||||
as this doesn't require a coupling to the <package>System.Web</package>
|
||||
namespace. In the case of Spring based web applications, Spring's
|
||||
<classname>WebSupportModule</classname> sets the storage strategy of
|
||||
<classname>LogicalThreadContext</classname> to be
|
||||
<classname>HybridContextStorage</classname>.</para>
|
||||
<literal>WebSupportModule</literal> sets the storage strategy of
|
||||
<literal>LogicalThreadContext</literal> to be
|
||||
<literal>HybridContextStorage</literal>.</para>
|
||||
</sect1>
|
||||
|
||||
<sect1>
|
||||
@@ -102,7 +119,7 @@
|
||||
interface which has two basic use cases. The first case is to block
|
||||
indefinitely until a condition is met:</para>
|
||||
|
||||
<programlisting>void ConcurrentRun(ISync lock) {
|
||||
<programlisting language="csharp">void ConcurrentRun(ISync lock) {
|
||||
lock.Acquire(); // block until condition met
|
||||
try {
|
||||
// ... access shared resources
|
||||
@@ -116,7 +133,7 @@
|
||||
<para>The other case is to specify a maximum amount of time to block
|
||||
before the condition is met:</para>
|
||||
|
||||
<programlisting>void ImpatientConcurrentRun(ISync lock) {
|
||||
<programlisting language="csharp">void ImpatientConcurrentRun(ISync lock) {
|
||||
// block for at most 10 milliseconds for condition
|
||||
if ( lock.Attempt(10) ) {
|
||||
try {
|
||||
@@ -143,7 +160,7 @@
|
||||
exiting from the block.</para>
|
||||
|
||||
<para>This should simplify the programming model for code using (!) an
|
||||
<literal>ISync</literal>: <programlisting>
|
||||
<literal>ISync</literal>: <programlisting language="csharp">
|
||||
ISync sync = ...
|
||||
...
|
||||
using (new SyncHolder(sync))
|
||||
@@ -152,7 +169,7 @@ using (new SyncHolder(sync))
|
||||
// holding the ISync lock
|
||||
}
|
||||
</programlisting> There is also the timed version, a little more
|
||||
cumbersome as you must deal with timeouts: <programlisting>
|
||||
cumbersome as you must deal with timeouts: <programlisting language="csharp">
|
||||
ISync sync = ...
|
||||
long msecs = 100;
|
||||
...
|
||||
@@ -184,7 +201,7 @@ catch (TimeoutException)
|
||||
unsignalled (Reset) and can only be <literal>Set()</literal>. A typical
|
||||
use is to act as a start signal for a group of worker threads.</para>
|
||||
|
||||
<programlisting>class Boss {
|
||||
<programlisting language="csharp">class Boss {
|
||||
Latch _startPermit;
|
||||
|
||||
void Worker() {
|
||||
@@ -222,7 +239,7 @@ catch (TimeoutException)
|
||||
keeps a count of the number available and acts accordingly. A typical
|
||||
use is to control access to a pool of shared objects.</para>
|
||||
|
||||
<programlisting>class LimitedConcurrentUploader {
|
||||
<programlisting language="csharp">class LimitedConcurrentUploader {
|
||||
// ensure we don't exceed maxUpload simultaneous uploads
|
||||
Semaphore _available;
|
||||
public LimitedConcurrentUploader(maxUploads) {
|
||||
|
||||
Reference in New Issue
Block a user