[英]Is ActiveRecord table_name thread safe?
I have a multi-threaded Rails application (using Sidekiq), and in each of the threads I am setting table_name for SomeModel to a different table name 我有一个多线程的Rails应用程序(使用Sidekiq),并且在每个线程中,我都将SomeModel的table_name设置为不同的表名。
Example: 例:
Thread 1:
SomeModel.table_name = "temp_table1"
Thread 2:
SomeModel.table_name = "temp_table2"
Is this thread-safe? 这是线程安全的吗?
In other words, if I set it to "temp_table1" in thread 1, is there anyway for thread 2 or another thread to see this change, or is it only applicable for thread 1? 换句话说,如果我在线程1中将其设置为“ temp_table1”,则无论如何线程2或其他线程都可以看到此更改,还是仅适用于线程1?
I'm using vanilla Ruby. 我正在使用香草红宝石。
Setting a variable in MRI is thread safe. 在MRI中设置变量是线程安全的。 Once you update the value at thread 1, all other threads will see this same value.
一旦在线程1更新了该值, 所有其他线程将看到该相同的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.