thread-local

Effect of ThreadLocals and side-by-side classloading

时光总嘲笑我的痴心妄想 提交于 2019-12-06 03:22:01
问题 Assuming class A{ private static final ThreadLocal<String> tl = new ThreadLocal<String>(); } If A is loaded in just one classloader on the vm, the value of t1 is obvious. But what happens to t1 if A is loaded side-by-side in two different classloaders ? Will the value be shared for a given thread ? 回答1: Interesting question. As Tom Hawtin - tackline explained, you are basically creating to instances of ThreadLocal<String>() . Now let's have a look at how ThreadLocal actually stores the values

Inheritable thread local in .NET

有些话、适合烂在心里 提交于 2019-12-05 19:41:48
.NET 4.0 introduced ThreadLocal<T> class, which is great. Now, my app use case requires something like Java's InheritableThreadLocal class. Is there anything like that in .NET? If not, how can a new thread initializes its thread locals variables with those from the parent thread? I suppose I need to make use the initialization factory method but not sure what to put in there. The closest thing I can think of is using ILogicalThreadAffinitive and storing your object in the thread's CallContext with CallContext.SetData. Object implementing ILogicalThreadAffinitive will flow across logical

Minimizing SecureRandom performance problems in multithreaded environment?

放肆的年华 提交于 2019-12-05 13:38:10
(This is with Java 8 and Tomcat 8 on SLES, FWIW.) How worried do I need to be about performance problems with SecureRandom (specifically the SHA1PRNG algorithm of the SUN provider) after the initial seeding when I am using a single SecureRandom instance in multiple threads? SecureRandom is thread-safe so that implies some level of potential contention? I don't see anything in Java 8 Javadocs that discusses this for SecureRandom though I see that the Javadocs for Random do specifically warn about contention and performance degradation when using a single Random instance across threads. We are

Spring Security: same SecurityContext-instance in multiple ThreadLocals, how does that work?

江枫思渺然 提交于 2019-12-05 13:33:17
Ive some questions about Spring Security 3.0.5 and the SecurityContext. First of all, Ill try to conclude what I know: SecurityContextHolder stores SecurityContext Between Request, SecurityContext is stored in HttpSession Begin of Request: SecurityContextHolder gets SecurityContext from HttpSession End of Request: SecurityContextHolder puts SecurityContext in HttpSession During the Request, on the server, SecurityContextHolder uses a ThreadLocal. Everywhere in the application (same request), the SecurityContext can be accessed Now my question.... --> Two Requests: the SecurityContext-instance

How to instantiate Spring bean with custom scope and @Autowired dependencies?

情到浓时终转凉″ 提交于 2019-12-05 07:16:48
问题 In our project, we use Spring request scoped beans. Now we've a requirement to support async requests and request scoped beans don't work for child threads. I'm aware of RequestContextFilter and it's "support" for async but it appears that RequestContextFilter expects the main thread to wait for the child threads to finish, which isn't the case for us. Our main thread immediately returns after spawning new threads using @Async annotation and DispatcherServlet clears out the

Track dead WebDriver instances during parallel task

夙愿已清 提交于 2019-12-05 04:49:39
问题 I am seeing some dead-instance weirdness running parallelized nested-loop web stress tests using Selenium WebDriver, simple example being, say, hit 300 unique pages with 100 impressions each. I'm "successfully" getting 4 - 8 WebDriver instances going using a ThreadLocal<FirefoxWebDriver> to isolate them per task thread, and MaxDegreeOfParallelism on a ParallelOptions instance to limit the threads. I'm partitioning and parallelizing the outer loop only (the collection of pages), and checking

How to get support for thread_local on Mac OSX clang?

和自甴很熟 提交于 2019-12-05 03:33:05
As shown in this answer , clang from Xcode on Mac OSX does not support thread_local storage even with C++11 flags set. Even on the latest version, Apple LLVM version 7.0.0 (clang-700.1.76), Target: x86_64-apple-darwin15.0.0, Thread model: posix, does not support thread_local : ../../src/dir/sysArch.h:1505:3: error: thread-local storage is not supported for the current target thread_local ^ rsfinn The version of clang supplied with Xcode 8 (and later) supports the thread_local keyword; see the discussion here . 来源: https://stackoverflow.com/questions/33358417/how-to-get-support-for-thread-local

New additional fields in java.lang.Thread, what is the idea?

自闭症网瘾萝莉.ら 提交于 2019-12-05 03:28:06
In Java 8, java.lang.Thread class got 3 new fields: /** The current seed for a ThreadLocalRandom */ @sun.misc.Contended("tlr") long threadLocalRandomSeed; /** Probe hash value; nonzero if threadLocalRandomSeed initialized */ @sun.misc.Contended("tlr") int threadLocalRandomProbe; /** Secondary seed isolated from public ThreadLocalRandom sequence */ @sun.misc.Contended("tlr") int threadLocalRandomSecondarySeed; as it said in Javadoc for being exclusively managed by class java.util.concurrent.ThreadLocalRandom . Furthermore, in ThreadLocalRandom they are used in very freakish way: SEED = UNSAFE

Is it OK to use ThreadLocal for storing the requested Locale?

北城余情 提交于 2019-12-05 02:26:16
I am working on internationalizing user entered data in a rather large Client/Server (HTTP (Hessian) is used for communication) application which is stored in a database. Users can choose the language they want to see and there is a default language which is used when a translation in the requested language is not present. Currently a data class may look like this: class MyDataClass { private Long id; private String someText; /* getters and setters */ } After internationalization it could look like this: class MyDataClass { private Long id; private Set<LocalizedStrings> localizedStrings; /*

Is thread-local storage persisted between backgroundworker invocations?

こ雲淡風輕ζ 提交于 2019-12-05 00:16:24
Are backgroundworker threads re-used? Specifically, if I set a named data slot (thread-local storage) during the DoWork() method of a backgroundworker, will the value of that data slot persist, potentially to be found be some other thread at a later time? I wouldn't have thought so, but I have this bug... EDIT: This blog post suggests that BackGroundWorker utilises a ThreadPool , which implies that Threads are re-used. So the question becomes; do re-used threads potentially persist thread-local storage between invocations? When the thread pool reuses a thread, it does not clear the data in