Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Azure CloudTable thread-safe?

I'm writing to Azure Table storage using Storage SDK 2.0 from different threads (ASP.NET application).

Is CloudTable object thread-safe? Can I initialize CloudStorageAccount, CloudTableClient and CloudTable only once (for example, in static constuctor) and then use them in different threads?

Or is it better to create all CloudStorageAccount, CloudTableClient and CloudTable objects each time from a blank (like it's shown in this article)? Does it affect the performance in any way?

What is a prefered way of getting instance of CloudTable each time executing an operation against the table?

like image 517
alexey Avatar asked Nov 06 '12 07:11

alexey


2 Answers

CloudStorageAccount

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

CloudTableClient

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

like image 153
Yossi Dahan Avatar answered Oct 16 '22 21:10

Yossi Dahan


  1. Unfortunately, they are not thread safe
  2. Fortunately, it doesn't matter at all: The communication is based on HTTP, which means no connection is reused and everytime the app just creates a new HTTP connection. So just recreate everything per thread. And I have tested even in one thread, recreating everything for each query just costs nothing more.
like image 28
AK913 Avatar answered Oct 16 '22 22:10

AK913