threadpool

Running a task in parallel to another task

我只是一个虾纸丫 提交于 2019-11-28 10:32:54
I have the following Foo class that uses FooProcessor class. So what i want to do is, while running cp1 instance process method, in parallel I want to run cp2.process() . public class Foo { public static void main(String [] args){ FooProcessor cp1 = new FooProcessor(); FooProcessor cp2 = new FooProcessor(); cp1.process(); // in parallel process cp2.process(); } } public class FooProcessor { public void process(){ System.out.println("Processing.."); } } However, i want cp1 sequentially, so i want it to run and complete, if cp2 doesnt complete or fails it is fine. If it doenst fail i want to

How to stop an executor thread when Tomcat is stopped?

旧巷老猫 提交于 2019-11-28 10:23:21
I am using an executor service by creating a fixed number of threads to do a HTTP GET data retrieval. executorService = ExecutorServiceFactory.getInstance().getExecutorService(Config.getInstance().getNumberOfThreads(), "ThreadExecutor_"+UIDFactory.getInstance().createSessionID()); executorService.execute(new Retrieve(data)); private class Retrieve implements Runnable{ private Vector<String> data; public WADORetrieve(Vector<String> data) { this.data = data; } @Override public void run() { for(int i=0;i<data.length;i++){ fetch(data[i]); } } } When Tomcat is stopped we get this error: SEVERE: The

TNonblockingServer, TThreadedServer and TThreadPoolServer, which one fits best for my case?

拜拜、爱过 提交于 2019-11-28 09:11:55
Our analytic server is written in c++. It basically queries underlying storage engine and returns a fairly big structured data via thrift. A typical requests will take about 0.05 to 0.6 seconds to finish depends on the request size. I noticed that there are a few options in terms of which Thrift server we can use in the c++ code, specifically TNonblockingServer, TThreadedServer, and TThreadPoolServer. It seems like TNonblockingServer is the way to go since it can support much more concurrent requests and still using a thread pool behind the scene to crunch through the tasks. It also avoids the

Always Running Threads on Windows Service

为君一笑 提交于 2019-11-28 08:48:11
I'm writing a Windows Service that will kick off multiple worker threads that will listen to Amazon SQS queues and process messages. There will be about 20 threads listening to 10 queues. The threads will have to be always running and that's why I'm leaning towards to actually using actual threads for the worker loops rather than threadpool threads. Here is a top level implementation. Windows service will kick off multiple worker threads and each will listen to it's queue and process messages. protected override void OnStart(string[] args) { for (int i = 0; i < _workers; i++) { new Thread

Java ExecutorService pause/resume a specific thread

余生长醉 提交于 2019-11-28 08:35:12
Is there a way to use ExecutorService to pause/resume a specific thread? private static ExecutorService threadpool = Executors.newFixedThreadPool(5); Imagine that I want to stop the thread wich as the id=0 (assuming that to each one is assigned an incremental id until the size of the threadpool is reached). After a while, by pressing a button let's say, I want to resume that specific thread and leave all the other threads with their current status, which can be paused or resumed. I have found on Java documentation a uncompleted version of PausableThreadPoolExecutor. But it doesn't suit what I

Time limit on individual threads with ExecutorService

混江龙づ霸主 提交于 2019-11-28 08:28:36
I have an ExecutorService managing a number of Callables. The tasks that the Callables run are mostly black box transformations and number crunching. Under certain conditions, the data being transformed will oscillate and the thread will take over an hour to finish. For comparison, most threads are completed within a minute. It's been deteremined that the data from the long-running threads is not relevent. I would like to interrupt any thread that runs longer than a certain amount of time. What would the best way to do this? Peter Lawrey Use a ScheduleExecutorService to schedule a task to

Specify task order execution in Java

北城以北 提交于 2019-11-28 08:25:32
I've searched a lot but couldn't find any solution. I use java thread pool in such way: ExecutorService c = Executors.newFixedThreadPool(3); for (int i = 0; i < 10; ++i) { c.execute(new MyTask(i)); } In such way Tasks are executed in consequent order (as in queue). But I need change "select next task" strategy. So I want assign to each task specify priority (it isn't thread priority) and execute tasks correspond to these priorities. So when executor have finished another task it chooses next task as task with maximum priority. It describes common problem. Maybe there is more simple approach

When ThreadPool.QueueUserWorkItem returns false

a 夏天 提交于 2019-11-28 08:10:01
问题 The MSDN states that the method returns true if the method is successfully queued; NotSupportedException is thrown if the work item is not queued. For testing purposes how to get the method to return false ? Or it is just a "suboptimal" class design? 回答1: In looking at the source code in Reflector, it seems the only part of the code that could return "false" is a call to the following: [MethodImpl(MethodImplOptions.InternalCall)] private static extern bool AdjustThreadsInPool(uint QueueLength

Executing a function periodically after the function completes its task

十年热恋 提交于 2019-11-28 07:48:54
问题 I am building a windows store app using C# and xaml. I need to refresh the data after certain interval of time (bring the new data from the server). I used ThreadPoolTimer to execute my refresh function periodically as follows: TimeSpan period = TimeSpan.FromMinutes(15); ThreadPoolTimer PeriodicTimer = ThreadPoolTimer.CreatePeriodicTimer(async(source)=> { n++; Debug.WriteLine("hello" + n); await dp.RefreshAsync(); //Function to refresh the data await Dispatcher.RunAsync(CoreDispatcherPriority

Threadpool in IIS context

孤街浪徒 提交于 2019-11-28 07:46:18
I have a general question about System.Threading.Threadpool when run in a webapplication on IIS. Say we have 2 requests execute at once, and we fire up a couple of threads through the ThreadPool.QueueUserWorkItem method. Will the two requests share the ThreadPool, or will the calls to the ThreadPool from the two requests operate in a two separate pools? This is in IIS6 and 7. Thanks for any insight. Here is a quote from the MSDN documentation about the ThreadPool class : There is one thread pool per process. The thread pool has a default size of 250 worker threads per available processor, and