threadpool

Java Threadpool vs. new Thread in high request scenario

情到浓时终转凉″ 提交于 2019-12-02 21:13:06
I have some old java code for a REST service that uses a separate thread for every incoming request. I.e. the main loop would loop on socket.accept() and hand off the socket to a Runnable which then would start up its own background thread and invoke run on itself. This worked admiringly well for a while until recently i noticed that the lag of accept to processing the request would get unacceptable under high load. When i say admiringly well, i mean that it was handling 100-200 requests a second without significant CPU usage. The performance only degraded when other daemons were adding load

How to solve Java error “pool-1-thread-xxxx” java.lang.OutOfMemory

岁酱吖の 提交于 2019-12-02 19:31:25
问题 I have searched the posts about this issue, but I did't see similar situation like mine. My java console shows the error message "pool-1-thread-xxxx" java.lang.OutOfMemory as the picture bellow: Red Line: CPU usage Green line: Memory usage I have increased the RAM from 6G to 10G , and set -Xms=8G -Xmx=8G -Xmn=3G in *.bat file before I start the program. I also keep watching performance monitor but the memory is always around 20%. I have no idea how could this happen. Any idea? Here is my run

Is it really my job to clean up ThreadLocal resources when classes have been exposed to a thread pool?

Deadly 提交于 2019-12-02 17:52:50
My use of ThreadLocal In my Java classes, I sometimes make use of a ThreadLocal mainly as a means of avoiding unnecessary object creation: @net.jcip.annotations.ThreadSafe public class DateSensitiveThing { private final Date then; public DateSensitiveThing(Date then) { this.then = then; } private static final ThreadLocal<Calendar> threadCal = new ThreadLocal<Calendar>() { @Override protected Calendar initialValue() { return new GregorianCalendar(); } }; public Date doCalc(int n) { Calendar c = threadCal.get(); c.setTime(this.then): // use n to mutate c return c.getTime(); } } I do this for the

Async-Await vs ThreadPool vs MultiThreading on High-Performance Sockets (C10k Solutions?)

删除回忆录丶 提交于 2019-12-02 17:44:43
I'm really confused about async-await s, pool s and thread s. The main problem starts with this question: "What can I do when I have to handle 10k socket I/O?" (aka The C10k Problem ). First, I tried to make a custom pooling architecture with threads that uses one main Queue and multiple Thread s to process all incoming datas. It was a great experience about understanding thread-safety and multi-threading but thread is an overkill with async-await nowadays. Later, I implemented a simple architecture with async-await but I can't understand why "The async and await keywords don't cause

Types of Thread Pools in java [closed]

大憨熊 提交于 2019-12-02 17:42:43
What are the types of thread pools in java. I need to implement a robust multi-threaded application which uses heavy computation, which thread pool should I use? There are various thread pools in java: Single Thread Executor : A thread pool with only one thread. So all the submitted tasks will be executed sequentially. Method : Executors.newSingleThreadExecutor() Cached Thread Pool : A thread pool that creates as many threads it needs to execute the task in parrallel. The old available threads will be reused for the new tasks. If a thread is not used during 60 seconds, it will be terminated

Reading a File without block main thead in GUI

一世执手 提交于 2019-12-02 16:57:35
问题 In my first attempt, I tried, failed, learned, and came back with the following attempt. I have a text file with the names parsed with commas that looks like this: Ann Marie,Smith,ams@companyname.com The list could have over 100+ names in it. I left out the code that generates all the other GUI components to focus on loading the combobox and the items. I'm trying to read a text and load the data into a combobox without blocking the main thread. I consulted a textbook and Pythons documentation

How can long running thread work inside web application

﹥>﹥吖頭↗ 提交于 2019-12-02 16:35:12
问题 So I have inside MVC controller method the following code : public ActionResult ProcessFile () { ThreadStart threadStart = new ThreadStart ( ()=>{ // Doing some long processing that takes 20 minute } ); Thread thread = new Thread(threadStart); thread.Start(); } The problem here is that when more than one request sent to this controller method the thread get killed. I need to Thread to stay working untill the processing ends , and it seem it is a matter of resources the much resources get

How to call a method async with some kind of priority?

半世苍凉 提交于 2019-12-02 14:49:49
问题 I need to call a couple of methods asynchronously with different priorities. My first idea was to use the ThreadPool and change the priority of the Thread like this: static void Run() { ThreadPool.QueueUserWorkItem(new WaitCallback(SomeMethod)); } static void SomeMethod(object o) { Thread.CurrentThread.Priority = ThreadPriority.BelowNormal; // is this ok? // do some work here } Does that work or what do you recommend? 回答1: According to http://msdn.microsoft.com/en-us/library/0ka9477y.aspx, it

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

北城余情 提交于 2019-12-02 14:27:58
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!"); System.out.println("Interrupted "+Thread.currentThread().getName()); e.printStackTrace(); } System

terminate called after throwing an instance of 'std::system_error' threadpool

a 夏天 提交于 2019-12-02 09:24:53
When I run my code : nb workers = 12 I'm i : 0 HELLO I'm func1 BYE I'm func2 terminate called after throwing an instance of 'std::system_error' what(): Invalid argument Aborted (core dumped) terminate called after throwing an instance of 'std::system_error'l what(): Invalid argument #ifndef CPP_PLAZZA_EXAMPLE_H #define CPP_PLAZZA_EXAMPLE_H #include <thread> #include <vector> #include <list> #include <memory> #include <functional> #include <mutex> #include <condition_variable> #include <atomic> #include <iterator> #include <tuple> class ThreadPool { public: ThreadPool(size_t numThreads);