threadpool

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

跟風遠走 提交于 2019-12-06 06:50:22
背景 当系统中的业务存在大量的相同任务(比如发送大量邮件),并且每个任务花费的时间也比较长,前段需要较快 的响应,针对这种需求,我们可以采用消息队列进行异步通知,同时也可以采用线程池+内存队列实现异步通知,处理业务问题。 代码实现 以下采用发送邮件作为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

using TBB for non-parallel tasks

我们两清 提交于 2019-12-06 06:45:47
问题 I want to get a thread-pool behavior using TBB. But whenever I read documents about TBB they always talk about parallel-for, parallel-dowhile etc. In contrast what I need is a main thread to assign tasks to a thread pool so those tasks will be executed 'on their own' - execute tasks asynchronously. Tasks here can be event handling for a GUI. Is the TBB task scheduler appropriate for such behavior? The impression I got from task scheduler is that it's only beneficial if I have tasks that can

PerThreadLifetimeManager in Unity

痞子三分冷 提交于 2019-12-06 06:27:18
In the Unity PerThreadLifetimeManager documentation, I read that: " This lifetime manager does not dispose the instances it holds ". Ref.: http://msdn.microsoft.com/en-us/library/ff647854.aspx So, if I am using a ThreadPool, does it mean that objects resolved using Unity on a Thread of the ThreadPool will not get disposed at the end of the work done in that thread before being returned to the pool? Any pattern or ideas how I can ensure that the objects do get disposed & I get a clean thread from the thread pool? Thanks! It depends on what type of lifetime manager. The PerThreadLifetimeManager

How to make a program not utilize 100% cpu?

倾然丶 夕夏残阳落幕 提交于 2019-12-06 06:07:50
There are 5 threads running in an infinite loop. 2 of them will send messages when queue is not empty. 4 of them will keep sending heartbeat within 5 minutes. 1 of them is to request data from another source. When it utilizes 100% of the CPU, I can not use any other applications in the window. The whole window becomes very slow. EDIT: can sleep be put after WaitOne? if(autoEvent.WaitOne()) { } else { } Thread.Sleep(100); Can sleep be put after subscriber.Recv() which is ZeroMQ ? all threads i put a sleep if no Recv(), however there is one thread i do not dare to put a sleep in realtime

How to print results of Python ThreadPoolExecutor.map immediately?

…衆ロ難τιáo~ 提交于 2019-12-06 06:07:25
I am running a function for several sets of iterables, returning a list of all results as soon as all processes are finished. def fct(variable1, variable2): # do an operation that does not necessarily take the same amount of # time for different input variables and yields result1 and result2 return result1, result2 variables1 = [1,2,3,4] variables2 = [7,8,9,0] with ThreadPoolExecutor(max_workers = 8) as executor: future = executor.map(fct,variables1,variables2) print '[%s]' % ', '.join(map(str, future)) >>> [ (12,3) , (13,4) , (14,5) , (15,6) ] How can I print intermediary results e.g. for

C# lower thread priority in thread pool

安稳与你 提交于 2019-12-06 04:36:18
问题 I have several low-imprtance tasks to be performed when some cpu time is available. I don't want this task to perform if other more import task are running. Ie if a normal/high priority task comes I want the low-importance task to pause until the importance task is done. There is a pretty big number of low importance task to be performed (50 to 1000). So I don't want to create one thread per task. However I believe that the threadpool do not allow some priority specification, does it ? How

Threadlocal memory leak in Threadpool

对着背影说爱祢 提交于 2019-12-06 04:32:34
问题 I am getting threadlocal memory leak errors in Tomcat and I am using ThreadPool, but have no implementation of ThreadLocal in my webapp. SEVERE: The web application [/myWebApp] created a ThreadLocal with key of type [org.a pache.http.impl.cookie.DateUtils$DateFormatHolder$1] (value [org.apache.http.imp l.cookie.DateUtils$DateFormatHolder$1@4c2849]) and a value of type [java.lang.re f.SoftReference] (value [java.lang.ref.SoftReference@1e67280]) but failed to rem ove it when the web application

Have Tomcat handle websocket calls in parallel, using different threads

懵懂的女人 提交于 2019-12-06 04:30:18
I have a Tomcat 8 websocket application and noticed a certain behavior when handling websocket client calls. Some details: http-nio-8080-exec-3 - 18:50:56 <-- this takes 30 seconds http-nio-8080-exec-3 - 18:50:56 <--+ http-nio-8080-exec-3 - 18:50:56 | http-nio-8080-exec-3 - 18:50:56 | http-nio-8080-exec-3 - 18:50:56 | http-nio-8080-exec-3 - 18:50:56 | http-nio-8080-exec-3 - 18:50:56 | http-nio-8080-exec-3 - 18:50:56 | http-nio-8080-exec-3 - 18:50:56 | http-nio-8080-exec-3 - 18:50:56 | http-nio-8080-exec-3 - 18:50:56 |- these take less than a http-nio-8080-exec-3 - 18:50:56 | second but get

Tomcat active threads pile up and stalls the server

断了今生、忘了曾经 提交于 2019-12-06 04:25:50
问题 We are having this issue with our production servers (apache-tomcat-7.0.6), which is running a Spring-JPA-Hibernate application using MySQL as DB. During this issue server becomes slow and within a minute it becomes unresponsive with number of active tomcat threads shoots up to 200(We use javamelody to observe these things). Logs look something like: 2012-04-07 07:53:48,058 DEBUG AuthenticationHandler:("http-bio-7006"-exec-304):35 - Authentication handler : ~ 2012-04-07 07:53:48,059 DEBUG

Nexus 5 going to sleep mode makes activity life cycle buggy

半腔热情 提交于 2019-12-06 04:10:43
问题 I have a strange behavior on the Nexus 5 when going in and out to the sleep mode. It kills and relaunchs the app in a really strange way. I show you the log: Going into sleep mode (pressing the power button) 17.005: E/MotherActivity(28940): onPause called 17.025: E/MotherActivity(28940): onStop called 17.315: E/MotherActivity(28940): onDestroy called 17.365: E/GameTuto1Activity(28940): MainActivity Constructor called 17.365: E/MotherActivity(28940): onCreate called 17.695: E/MotherActivity