|
4 | 4 | using System.IO; |
5 | 5 | using System.Runtime.Serialization; |
6 | 6 | using System.Runtime.Serialization.Formatters.Binary; |
| 7 | +using System.Threading; |
7 | 8 | using Microsoft.Spark.Interop; |
8 | 9 | using Microsoft.Spark.Interop.Ipc; |
9 | 10 | using Microsoft.Spark.Services; |
@@ -261,28 +262,26 @@ internal static void Remove(long bid) |
261 | 262 | /// </summary> |
262 | 263 | internal static class JvmBroadcastRegistry |
263 | 264 | { |
264 | | - [ThreadStatic] |
265 | | - private static readonly List<JvmObjectReference> s_jvmBroadcastVariables = |
266 | | - new List<JvmObjectReference>(); |
| 265 | + private static ThreadLocal<List<JvmObjectReference>> s_jvmBroadcastVariables = |
| 266 | + new ThreadLocal<List<JvmObjectReference>>(() => new List<JvmObjectReference>()); |
267 | 267 |
|
268 | 268 | /// <summary> |
269 | 269 | /// Adds a JVMObjectReference object of type <see cref="Broadcast{T}"/> to the list. |
270 | 270 | /// </summary> |
271 | 271 | /// <param name="broadcastJvmObject">JVMObjectReference of the Broadcast variable</param> |
272 | 272 | internal static void Add(JvmObjectReference broadcastJvmObject) => |
273 | | - s_jvmBroadcastVariables.Add(broadcastJvmObject); |
| 273 | + s_jvmBroadcastVariables.Value.Add(broadcastJvmObject); |
274 | 274 |
|
275 | 275 | /// <summary> |
276 | 276 | /// Clears s_jvmBroadcastVariables of all the JVMObjectReference objects of type |
277 | 277 | /// <see cref="Broadcast{T}"/>. |
278 | 278 | /// </summary> |
279 | | - internal static void Clear() => s_jvmBroadcastVariables.Clear(); |
| 279 | + internal static void Clear() => s_jvmBroadcastVariables.Value.Clear(); |
280 | 280 |
|
281 | 281 | /// <summary> |
282 | 282 | /// Returns the static member s_jvmBroadcastVariables. |
283 | 283 | /// </summary> |
284 | 284 | /// <returns>A list of all broadcast objects of type <see cref="JvmObjectReference"/></returns> |
285 | | - internal static List<JvmObjectReference> GetAll() => s_jvmBroadcastVariables; |
| 285 | + internal static List<JvmObjectReference> GetAll() => s_jvmBroadcastVariables.Value; |
286 | 286 | } |
287 | 287 | } |
288 | | - |
0 commit comments