threadpool

InheritableThreadLocal and thread pools

感情迁移 提交于 2019-11-29 04:02:33
I have a problem which I don't really think has a solution but I'll try here anyway. My application uses a thread pool and some of the threads in this pool have an inheritable thread local variable. I've extended the ThreadPoolExecutor class to essentially clear out the thread local variable (in the afterExecute call back method) when a thread is done executing. I understand that when you have an InheritableThreadLocal variable, the childValue() method is called when the thread is initialized to get the ThreadLocal variable's value from the parent thread. However, in my case the next time the

Connection pool and File handles

旧时模样 提交于 2019-11-29 03:59:48
问题 We use Retrofit/OkHttp3 for all network traffic from our Android application. So far everything seems to run quite smoothly. However, we have now occasionally had our app/process run out of file handles. Android allows for a max of 1024 file handles per process OkHttp will create a new thread for each async call Each thread created this way will (from our observation) be responsible for 3 new file handles (2 pipes and one socket). We were able to debug this exactly, where each dispached async

With ThreadPoolExecutor, how to get the name of the thread running in the thread pool?

五迷三道 提交于 2019-11-29 03:59:28
I'm using a ThreadPoolExecutor in Java to manage a lot of running threads. I've created my own simple ThreadFactory so I can give the threads better names. The issue is that the name gets set in the Thread when the thread pool is first created and is not tied to the task that the thread pool is actually running. I understand this... my Runnables and Callables--though they have names--are actually one level of abstraction down from the ThreadPoolExecutor 's running threads. There have been some other questions on StackOverflow about creating names for ThreadPoolExecutor thread pools. (See How

Java `OutOfMemoryError` when creating < 100 threads

前提是你 提交于 2019-11-29 03:54:34
I've been reading and testing and banging my head on the wall for over a day because of this error. I have some Java code in a class called Listener that looks like this ExecutorService executor = Executors.newFixedThreadPool(NTHREADS); boolean listening = true; int count = 0; while (listening) { Runnable worker; try { worker = new ServerThread(serverSocket.accept()); // this is line 254 executor.execute(worker); count++; logger.info("{} threads started", count); } catch (Exception e1){ //... } } I have been tweaking the JVM settings -Xmx (anywhere from 1 to 15G) and -Xss (anywhere from 104k

Python multiprocessing pool inside daemon process

我的梦境 提交于 2019-11-29 02:37:32
I opened up a question for this problem and did not get a thorough enough answer to solve the issue (most likely due to a lack of rigor in explaining my issues which is what I am attempting to correct): Zombie process in python multiprocessing daemon I am trying to implement a python daemon that uses a pool of workers to executes commands using Popen . I have borrowed the basic daemon from http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/ I have only changed the init , daemonize (or equally the start ) and stop methods. Here are the changes to the init method: def _

聊聊dubbo的AllDispatcher

China☆狼群 提交于 2019-11-29 01:49:14
序 本文主要研究一下dubbo的AllDispatcher Dispatcher dubbo-2.7.3/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/Dispatcher.java @SPI(AllDispatcher.NAME) public interface Dispatcher { /** * dispatch the message to threadpool. * * @param handler * @param url * @return channel handler */ @Adaptive({Constants.DISPATCHER_KEY, "dispather", "channel.handler"}) // The last two parameters are reserved for compatibility with the old configuration ChannelHandler dispatch(ChannelHandler handler, URL url); } Dispatcher接口定义了dispatch方法,返回ChannelHandler AllDispatcher dubbo-2.7.3/dubbo-remoting

Controlling scheduling priority of python threads?

一曲冷凌霜 提交于 2019-11-29 01:23:40
I've written a script that uses two thread pools of ten threads each to pull in data from an API. The thread pool implements this code on ActiveState . Each thread pool is monitoring a Redis database via PubSub for new entries. When a new entry is published, python passes the data to a function that uses python's Subprocess.POpen to execute a PHP shell to do the actual work of calling the API. This system of launching PHP shells is necessary for functionality with my PHP web app, so launching PHP shells with Python can't be avoided. This script will only be running on Linux servers. How do I

Performance Issues with newFixedThreadPool vs newSingleThreadExecutor

两盒软妹~` 提交于 2019-11-29 01:16:13
问题 I am trying to Benchmark our Client code. So I decided I will write a multithreading program to do the benchmarking of my client code. I am trying to measure how much time (95 Percentile) below method will take- attributes = deClient.getDEAttributes(columnsList); So below is the multithreaded code I wrote to do the benchmarking on the above method. I am seeing lot of variations in my two scenarios- 1) Firstly, with multithreaded code by using 20 threads and running for 15 minutes . I get 95

周期性线程池与主要源码解析

扶醉桌前 提交于 2019-11-28 23:57:01
之前学习ThreadPool的使用以及源码剖析,并且从面试的角度去介绍知识点的解答。今天小强带来周期性线程池的使用和重点源码剖析。 ScheduledThreadPoolExecutor ScheduledThreadPoolExecutor:用来处理延时任务或定时任务 定时线程池类的类结构图 ScheduledThreadPoolExecutor接收ScheduleFutureTask类型的任务,是线程池调度任务的最小单位。 它采用DelayQueue存储等待的任务: 1、DelayQueue内部封装成一个PriorityQueue,它会根据time的先后时间顺序,如果time相同则根绝sequenceNumber排序; 2、DelayQueue是无界队列; ScheduleFutureTask 接收的参数: private final long sequenceNumber;//任务的序号 private long time;//任务开始的时间 private final long period;//任务执行的时间间隔 工作线程的的执行过程: 工作线程会从DelayQueue取出已经到期的任务去执行; 执行结束后重新设置任务的到期时间,再次放回DelayQueue; ScheduledThreadPoolExecutor会把待执行的任务放到工作队列DelayQueue中

what's the proper way to use a ThreadPool?

旧巷老猫 提交于 2019-11-28 22:56:16
If my understanding of the way the ThreadPool works is correct, one of its purposes is to limit the number of worker threads within a process that can be created at a given time. For example, if you set MaxThreads to 5 and then call QueueUserWorkItem 30 times, 30 requests will be made to the ThreadPool, but only 5 of those requests will be serviced by a new thread, while the other 25 requests will be added to the queue and serviced one at time as previous requests complete and existing threads becomes available. In the code below, however, the call to Thread.Sleep(-1) guarantees that the