threadpool

glassfish/tomcat Java Server load class once

人走茶凉 提交于 2020-01-06 14:05:03
问题 I am using glassfish v2 but I've had the same problem in tomcat. Once the server starts, I see: sudo jmap -histo:live 14127 | grep KVStore 6222: 1 24 xxx.xxx.KVStore After a while of usage, I get: sudo jmap -histo:live 14127 | grep KVStore 7240: 1 24 xxx.xxx.KVStore 7360: 1 24 xxx.xxx.KVStore While I'm guessing this has something to do with how glassfish scales out, this is really problematic because I use the KVStore as an in memory storage class. It is a singleton class with a static

glassfish/tomcat Java Server load class once

笑着哭i 提交于 2020-01-06 14:01:45
问题 I am using glassfish v2 but I've had the same problem in tomcat. Once the server starts, I see: sudo jmap -histo:live 14127 | grep KVStore 6222: 1 24 xxx.xxx.KVStore After a while of usage, I get: sudo jmap -histo:live 14127 | grep KVStore 7240: 1 24 xxx.xxx.KVStore 7360: 1 24 xxx.xxx.KVStore While I'm guessing this has something to do with how glassfish scales out, this is really problematic because I use the KVStore as an in memory storage class. It is a singleton class with a static

分布式系统中如何优雅地追踪日志(原理篇)

故事扮演 提交于 2020-01-06 13:55:43
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> > 本文只讲原理,不讲框架。 分布式系统中日志追踪需要考虑的几个点? 需要一个全服务唯一的id,即traceId,如何保证? traceId如何在服务间传递? traceId如何在服务内部传递? traceId如何在多线程中传递? 我们一一来解答: 全服务唯一的traceId,可以使用uuid生成,正常来说不会出现重复的; 关于服务间传递,对于调用者,在协议头加上traceId,对于被调用者,通过前置拦截器或者过滤器统一拦截; 关于服务内部传递,可以使用ThreadLocal传递traceId,一处放置,随处可用; 关于多线程传递,分为两种情况: 子线程,可以使用InheritableThreadLocal 线程池,需要改造线程池对提交的任务进行包装,把提交者的traceId包装到任务中 比如,上面这个系统,系统入口在A处,A调用B的服务,B里面又起了一个线程B1去访问D的服务,B本身又去访问C服务。 我们就可以这么来跟踪日志: 所有服务都需要一个全局的InheritableThreadLocal保存服务内部traceId的传递; 所有服务都需要一个前置拦截器或者过滤器,检测如果请求头没有traceId就生成一个,如果有就取出来,并把traceId放到全局的InheritableThreadLocal里面;

Division of a task to threads - multi threading

六眼飞鱼酱① 提交于 2020-01-05 10:05:27
问题 I want to generate pairs from a given large pool of numbers. I am using two for loops and threads. My function getAllPairs() in the code generates apairs with a given array of numbers. I have an array of length 1000. With one thread, output time is nearly 15 sec. Now I want to use 5-6 threads and reduce this output time.I am stuck at dividing this task equally to five threads.If not threads,how to decrease the output time? Solution with threads is appreciated since I put a lot of time

How can I Distribute the mutex lock between processes?

五迷三道 提交于 2020-01-05 07:27:26
问题 I am trying to achieve synchronization between different processes. Multiple process calling ProcessLock should be synchronized. I am able to achieve it. But problem here is that Other threads are unable to enter critical section. Lock is always acquired by same application. How can I share the lock between different application. public class ProcessLock : IDisposable { // the name of the global mutex; private const string MutexName = "FAA9569-7DFE-4D6D-874D-19123FB16CBC-8739827-

Custom thread pool supporting async actions

旧时模样 提交于 2020-01-04 14:17:26
问题 I would like to have a custom thread pool satisfying the following requirements: Real threads are preallocated according to the pool capacity. The actual work is free to use the standard .NET thread pool, if needed to spawn concurrent tasks. The pool must be able to return the number of idle threads. The returned number may be less than the actual number of the idle threads, but it must not be greater. Of course, the more accurate the number the better. Queuing work to the pool should return

Python multiprocessing: object passed by value?

狂风中的少年 提交于 2020-01-04 06:04:49
问题 I have been trying the following: from multiprocessing import Pool def f(some_list): some_list.append(4) print 'Child process: new list = ' + str(some_list) return True if __name__ == '__main__': my_list = [1, 2, 3] pool = Pool(processes=4) result = pool.apply_async(f, [my_list]) result.get() print 'Parent process: new list = ' + str(my_list) What I get is: Child process: new list = [1, 2, 3, 4] Parent process: new list = [1, 2, 3] So, it means that the my_list was passed by value since it

Python multiprocessing: object passed by value?

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-04 06:04:07
问题 I have been trying the following: from multiprocessing import Pool def f(some_list): some_list.append(4) print 'Child process: new list = ' + str(some_list) return True if __name__ == '__main__': my_list = [1, 2, 3] pool = Pool(processes=4) result = pool.apply_async(f, [my_list]) result.get() print 'Parent process: new list = ' + str(my_list) What I get is: Child process: new list = [1, 2, 3, 4] Parent process: new list = [1, 2, 3] So, it means that the my_list was passed by value since it

What Thread sleep method is most precise: Monitor.Wait vs System.Timer vs DispatchTimer vs Threading.Timer

大兔子大兔子 提交于 2020-01-04 01:57:07
问题 What .NET object (or technique) is the most precise at launching a thread every XXX milliseconds? What are the tradeoffs? For example: int maxDurationMs = 1000; while (true) { DateTime dt = DateTime.UtcNow; DoQuickStuff() TimeSpan duration1 = DateTime.UtcNow - dt; int sleepTime = maxDurationMs - duration1.Milliseconds; if (sleepTime > 0) System.Threading.Thread.Sleep(sleepTime); } or // CPU Intensive, but fairly accurate int maxDurationMs = 1000; while (true) { DateTime dt = DateTime.UtcNow;

Why is creating a new thread expensive?

霸气de小男生 提交于 2020-01-03 17:10:19
问题 I read lots of .Net resources telling me that I should be using a thread pool thread rather than instantiating a new thread myself. They say you should do this because instantiating a new thread is an expensive operation. What happens during thread creation that makes it an expensive operation? 回答1: Everything is relative. Creating a new thread is expensive... relative to not creating one. If you're not doing a lot of work per thread, the work involved in building and tearing down the threads