threadpool

使用线程池+内存队列实现异步处理业务问题

人盡茶涼 提交于 2019-12-03 02:28:10
背景 当系统中的业务存在大量的相同任务(比如发送大量邮件),并且每个任务花费的时间也比较长,前端需要较快 的响应,针对这种需求,我们可以采用消息队列进行异步通知,同时也可以采用线程池+内存队列实现异步通知,处理业务问题。 代码实现 以下采用发送邮件作为demo 邮箱实体类 @Data public class Email implements Serializable { private static final long serialVersionUID = 1L; /** * 自增主键 */ private Long id; /** * 接收人邮箱(多个逗号分开) */ private String receiveEmail; /** * 主题 */ private String subject; /** * 发送内容 */ private String content; /** * 模板 */ private String template; /** * 发送时间 */ private Timestamp sendTime; } 邮件队列 public class MailQueue { //队列大小 static final int QUEUE_MAX_SIZE = 1000; static BlockingQueue<Email> blockingQueue = new

Analyzing output of !threadpool and !threads in windbg

允我心安 提交于 2019-12-03 02:15:35
I have generated dumps on four servers and am analyzing the output of !threadpool and !threads. I noticed the roughly consistent following output: 0:024> !threadpool CPU utilization 0% Worker Thread: Total: 2 Running: 0 Idle: 2 MaxLimit: 200 MinLimit: 2 Work Request in Queue: 0 Number of Timers: 27 Completion Port Thread:Total: 2 Free: 0 MaxFree: 4 CurrentLimit: 2 MaxLimit: 200 MinLimit: 2 !threads -special ThreadCount: 32 UnstartedThread: 0 BackgroundThread: 19 PendingThread: 0 DeadThread: 13 Hosted Runtime: no My questions are: 1)How can I determine what the source of those 27 timers are? 2

How to name the threads of a thread pool in Java [duplicate]

◇◆丶佛笑我妖孽 提交于 2019-12-03 01:04:16
This question already has an answer here: Naming threads and thread-pools of ExecutorService 17 answers I have a Java application that uses the Executor framework and I have code that looks like this protected ScheduledExecutorService scheduledExecutorService = new ScheduledThreadPoolExecutor(5) My understanding is that internally the JVM would create a pool of 5 threads. Now when I check the execution in a profiler, I get something like thread-pool2,thread-pool3 and so on. Some of these thread pools are created by the server and some are created by me , I need a way to differentiate which

What is the difference between ExecutorService.submit and ExecutorService.execute in this code in Java?

眉间皱痕 提交于 2019-12-03 01:00:46
问题 I am learning to use ExectorService to pool threads and send out tasks. I have a simple program below import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; class Processor implements Runnable { private int id; public Processor(int id) { this.id = id; } public void run() { System.out.println("Starting: " + id); try { Thread.sleep(5000); } catch (InterruptedException e) { System.out.println("sorry, being interupted, good bye!")

TensorFlow Execution on a single (multi-core) CPU Device

落花浮王杯 提交于 2019-12-03 00:49:15
I have some questions regarding the execution model of TensorFlow in the specific case in which there is only a CPU device and the network is used only for inference, for instance using the Image Recognition( https://www.tensorflow.org/tutorials/image_recognition ) C++ Example with a multi-core platform. In the following, I will try to summarize what I understood, while asking some questions. Session->Run() (file direct_session.cc) calls ExecutorState::RynAsynch, which initializes the TensorFlow ready queue with the roots nodes. Then, the instruction runner_([=]() { Process(tagged_node,

How to pin threads to cores with predetermined memory pool objects? (80 core Nehalem architecture 2Tb RAM)

泄露秘密 提交于 2019-12-02 23:11:15
I've run into a minor HPC problem after running some tests on a 80core (160HT) nehalem architecture with 2Tb DRAM: A server with more than 2 sockets starts to stall a lot (delay) as each thread starts to request information about objects on the "wrong" socket, i.e. requests goes from a thread that is working on some objects on the one socket to pull information that is actually in the DRAM on the other socket. The cores appear 100% utilized, even though I know that they are waiting for the remote socket to return the request. As most of the code runs asynchronously it is a lot easier to

Creating a dynamic (growing/shrinking) thread pool

混江龙づ霸主 提交于 2019-12-02 22:57:29
I need to implement a thread pool in Java (java.util.concurrent) whose number of threads is at some minimum value when idle, grows up to an upper bound (but never further) when jobs are submitted into it faster than they finish executing, and shrinks back to the lower bound when all jobs are done and no more jobs are submitted. How would you implement something like that? I imagine that this would be a fairly common usage scenario, but apparently the java.util.concurrent.Executors factory methods can only create fixed-size pools and pools that grow unboundedly when many jobs are submitted. The

Server 2008 RC2, IIS 7.5, ASP.NET and Requests Queued Poor Performance

只谈情不闲聊 提交于 2019-12-02 22:14:21
I already know the answer to this, but wanted to share with the community since it is NOT documented from Microsoft. The scenario: A surge of traffic hits your IIS 7.5 ASP.NET website, and you notice that requests start queuing up. The performance of the site slows to a crawl, yet you have plenty of CPU and RAM available. This is the problem we saw recently with a site that made a bunch of internal web-service calls. An internal health check would start timing-out, which would cause this server to drop out of our cluster. (However, this server is the most powerful hardware of the bunch ...)

How do I manage ruby threads so they finish all their work?

梦想与她 提交于 2019-12-02 21:17:25
I have a computation that can be divided into independent units and the way I'm dealing with it now is by creating a fixed number of threads and then handing off chunks of work to be done in each thread. So in pseudo code here's what it looks like # main thread work_units.take(10).each {|work_unit| spawn_thread_for work_unit} def spawn_thread_for(work) Thread.new do do_some work more_work = work_units.pop spawn_thread_for more_work unless more_work.nil? end end Basically once the initial number of threads is created each one does some work and then keeps taking stuff to be done from the work

Why doesn't Ruby have a ThreadPool built-in?

霸气de小男生 提交于 2019-12-02 21:13:34
I have a program that creates 10000 threads at once, and runs 8 at the same time. But ruby doesn't have a ThreadPool built-in as Java. Is there a good reason? Raindog Most likely the reason is because ruby doesn't have "real" threads. It has what are called Green threads. The ruby interpreter takes care of scheduling execution threads without using any underlying OS threads. This effectively makes Ruby single threaded. probably because it's easy to roll your own using the standard library "Queue" class. q = Queue.new 3.times { Thread.new { while something = q.pop(true) rescue nil; ... } It's a