threadpool

Asynchronous code, shared variables, thread-pool threads and thread safety

笑着哭i 提交于 2019-12-05 02:59:20
When I write asynchronous code with async/await, usually with ConfigureAwait(false) to avoid capturing the context, my code is jumping from one thread-pool thread to the next after each await . This raises concerns about thread safety. Is this code safe? static async Task Main() { int count = 0; for (int i = 0; i < 1_000_000; i++) { Interlocked.Increment(ref count); await Task.Yield(); } Console.WriteLine(count == 1_000_000 ? "OK" : "Error"); } The variable i is unprotected, and is accessed by multiple thread-pool threads*. Although the pattern of access is non-concurrent, it should be

C# Catching exception which is occurring on ThreadPool

六月ゝ 毕业季﹏ 提交于 2019-12-05 01:31:26
I am investigating some crashes in my application caused by a Win32 exception, and I have narrowed it down that it must be occurring in the threadpool which is taking care of the EventLog.EntryWrittenEventHandler event handler in my application. I set this up like this: // Create the event log monitor eventLog.Log = "Application"; eventLog.EnableRaisingEvents = true; eventLog.EntryWritten += new EntryWrittenEventHandler(EventLogMonitor); EventLogMonitor is the handler for my event. I am wondering does anybody have any ideas as to where I could find out whats causing this exception. It seems

Caused by: java.lang.OutOfMemoryError: Java heap space

 ̄綄美尐妖づ 提交于 2019-12-05 01:19:37
问题 MY GOAL: I want run my application for 1000 users. NOW I am trying to run for 100 user. During application run, I'd like to do some process for each user that will take a minimum of one hour per user, so I'm using one thread per user. ERROR Caused by: java.lang.OutOfMemoryError: Java heap space I've tried to figure out what this means, but I'm not really sure how to resolve it. Can anybody help me? 回答1: This error means that your program needs more memory than your JVM allowed it to use!

How to restart schedule when scheduleWithFixedDelay throws an exception?

最后都变了- 提交于 2019-12-05 00:51:33
问题 I use ScheduledExecutorService to schedule some tasks which need to run periodically. I want to know whether this code works to recover the schedule when an exception happens. ScheduledExecutorService service = Executors.newScheduledThreadPool(1); this.startMemoryUpdateSchedule(service);//See below method //Recursive method to handle exception when run schedule task private void startMemoryUpdateSchedule(ScheduledExecutorService service) { ScheduledFuture<?> future = service

Does .NET ThreadPool thread get reset when it goes back to the pool?

淺唱寂寞╮ 提交于 2019-12-05 00:30:10
When a thread pool thread is done, does stuff like Name or thread local data get reset? So when the thread comes out of the pool next time, it's like brand new? Is there an "official" documentation on this aspect of the ThreadPool threads? It does NOT clear thread local storage when it's released, which is the most important aspect to note. http://msdn.microsoft.com/en-us/library/system.threading.threadpool.aspx When the thread pool reuses a thread, it does not clear the data in thread local storage or in fields that are marked with the ThreadStaticAttribute attribute. Therefore, data that is

ThreadPoolExecutor with ArrayBlockingQueue

允我心安 提交于 2019-12-05 00:07:33
问题 I started reading more about ThreadPoolExecutor from Java Doc as I am using it in one of my project. So Can anyone explain me what does this line means actually?- I know what does each parameter stands for, but I wanted to understand it in more general/lay-man way from some of the experts here. ExecutorService service = new ThreadPoolExecutor(10, 10, 1000L, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10, true), new ThreadPoolExecutor.CallerRunsPolicy()); Updated:- Problem

What is the difference between “seda + concurrentConsumers” and “direct + threads”

旧巷老猫 提交于 2019-12-04 23:57:03
问题 Apache Camel provide two solutions for using thread pool: from("seda:stageName?concurrentConsumers=5").process(...) and from("direct:stageName").thread(5).process(...) I would like to know, what is the difference between the two solutions ? Is it just two kind of write the same thing or not ? What are the use cases ? 回答1: SEDA Component The seda: component provides asynchronous SEDA behavior so that messages are exchanged on a BlockingQueue and consumers are invoked in a separate thread to

Is there an implementation of std::async which uses thread pool?

£可爱£侵袭症+ 提交于 2019-12-04 21:25:13
The standard function std::async : The template function async runs the function f asynchronously (potentially in a separate thread which may be part of a thread pool) and returns a std::future that will eventually hold the result of that function call. There is two launch polices std::launch::async and std::launch::deferred . In my compiler's ( GCC 6.2 ) standard library impelmentation, the first one always creates a new thread and the second one does lazy evaluation on the calling thread. By default std::launch::deferred is used. Is there some implementation which uses thread pool with size

How to manage Thread Local Storage (TLS) when using TPL?

此生再无相见时 提交于 2019-12-04 18:19:53
问题 I want to store logging context information in TLS so that I can set a value at the entry point, and have that value available in all resulting stacks. This work well, but I also using TPL and the ThreadPool. The problem then becomes how to migrate TLS data to the other threads. I can do it all myself, but then I lose nice methods like Parallel.For. Is there some way to have TLS copied when using TPL? This will also apply to C# when it gets the await feature. Thanks, Erick 回答1: Typically,

Thread creation in JavaEE EJB/Web containers

萝らか妹 提交于 2019-12-04 17:35:29
I read in Adam Bien's JavaEE night hacks book that while thread creation is prohibited on EJB containers, this is not the case for web containers. He actually creates a thread pool executor in his x-ray probe which runs on Tomcat. I'm a little confused now. While I faced situations in which I had to do manual thread-pool management in an EE app, I can somehow understand why it would be a bad idea to manually create threads in a JavaEE container. However, I don't understand the difference between an EJB container and a web container respecting thread creation when you can deploy a great portion