jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1306606 - /incubator/jena/site/trunk/content/jena/documentation/tdb/tdb_transactions.mdtext
Date Wed, 28 Mar 2012 21:39:15 GMT
Author: andy
Date: Wed Mar 28 21:39:14 2012
New Revision: 1306606

URL: http://svn.apache.org/viewvc?rev=1306606&view=rev
Log:
Use examples in the multi-threade section

Modified:
    incubator/jena/site/trunk/content/jena/documentation/tdb/tdb_transactions.mdtext

Modified: incubator/jena/site/trunk/content/jena/documentation/tdb/tdb_transactions.mdtext
URL: http://svn.apache.org/viewvc/incubator/jena/site/trunk/content/jena/documentation/tdb/tdb_transactions.mdtext?rev=1306606&r1=1306605&r2=1306606&view=diff
==============================================================================
--- incubator/jena/site/trunk/content/jena/documentation/tdb/tdb_transactions.mdtext (original)
+++ incubator/jena/site/trunk/content/jena/documentation/tdb/tdb_transactions.mdtext Wed Mar
28 21:39:14 2012
@@ -94,7 +94,7 @@ The `dataset.end()` declares the end of 
 `dataset.commit()` or `dataset.abort()` which all have the same effect for a read transaction.
 
      Location location = ... ;
-     Dataset dataset =  TDBFactory.create(location) ;
+     Dataset dataset = ... ;
      dataset.begin(ReadWrite.READ) ;
         
      try {
@@ -137,7 +137,7 @@ needs to start a new transaction to perf
 dataset.
 
      Location location = ... ;
-     Dataset dataset =  TDBFactory.create(location) ;
+     Dataset dataset = ... ;
      dataset.begin(ReadWrite.WRITE) ;
         
      try {
@@ -175,17 +175,33 @@ dataset.
 
 ## Multi-threaded use
 
-While it is possible to shared a write transaction between multiple
-threads, this is not encouraged. Applications needing to do so must
-ensure that within the transaction, all threads are acting
-"multiple reader OR single writer". Change to the data within the
-transaction must be executed one at a time.
-
-It is better not to share the same Dataset reference between different 
-threads. Dataset objects are quite cheap to create via 
-TDBFactory.create(location) and this ensure correct transaction
-handling. If, for some reason, in-memory TDB databases are needed, 
-then the use of "named memory locations" is recommended: Location.mem("X").  
+The usual idiom for working with multi-threaded applications is to have 
+one dataset per thread.  There is one transaction per datset object.
+
+Thread 1:
+
+     Dataset dataset = TDBFactory.createDataset(location) ;
+     dataset.begin(ReadWrite.WRITE) ;
+     try {
+       ...
+       dataset.commit() ;
+     } finally { dataset.end() ; }
+
+Thread 2:
+
+     Dataset dataset = TDBFactory.createDataset(location) ;
+     dataset.begin(ReadWrite.READ) ;
+     try {
+       ...
+     } finally { dataset.end() ; }
+
+Each thread has a separate `dataset` object; these share internally the 
+same storage but each can have it's own transaction.
+
+While it is possible to shared a transaction between multiple
+threads, this is not encouraged.  Applications needing to do so must
+ensure that only one thread starts the transaction, via a `Dataset` object,
+and that all threads are acting "multiple reader OR single writer". 
 
 ## Multi JVM
 



Mime
View raw message