executorservice

Naming threads and thread-pools of ExecutorService

ε祈祈猫儿з 提交于 2019-12-27 10:42:41
问题 Let's say I have an application that utilizes the Executor framework as such Executors.newSingleThreadExecutor().submit(new Runnable(){ @Override public void run(){ // do stuff } } When I run this application in the debugger, a thread is created with the following (default) name: Thread[pool-1-thread-1] . As you can see, this isn't terribly useful and as far as I can tell, the Executor framework does not provide an easy way to name the created threads or thread-pools. So, how does one go

Create a Job Queue or Task Controller and dynamically add task to it in Java

旧时模样 提交于 2019-12-25 07:41:10
问题 Hi all I want to create a job queue to execute multiple task.but,my requirement is i should be able to add tasks to that job queue any time and all those tasks should be executed sequentially. I searched some solutions in internet and found these two links 1)Java Thread Pool Executor Example 2)Java Executor Framework Tutorial and Best Practices. But i can't use both of these solution.Because after starting Executor service I can't add new task to the service. Because we know that It may throw

App keeps trying to restart message service, how do I run the message service only once?

妖精的绣舞 提交于 2019-12-24 11:15:40
问题 I have an app that runs an executor service with 2 runnables that start the process to receive messages from a rfid reader. This reader receives a message from the messagelistener that contains the tag information after the tag has gone by the reader. I receive the tag information but I receive an error while its running bc it keeps trying to restart the messagelistenerservice. Tried to only add the code that needs to be seen. How do I just start the messagelistener service once so I don't

Pause and resume a ScheduledExecutorService

主宰稳场 提交于 2019-12-24 04:27:45
问题 I'm writing a tetris-clone. I want to make the pieces fall a tad faster after every 60 seconds, and for this I'm using a ScheduledExecutorService: executor.scheduleAtFixedRate(new Runnable() { @Override public void run() { levelUp(); } }, 60, 60, TimeUnit.SECONDS); Now, I can pause the game, and while paused the game obviously stops doing anything until I resume it. As it is now, pausing the game is well and all for everything but this executor taking care of "leveling up". For example, if I

How do I know when ExecutorService has finished if items on the ES can resubmit to the ES

两盒软妹~` 提交于 2019-12-24 04:14:11
问题 My Java application works on music files within folders, it is designed to process multiple folders in parallel and independently. To do this each folder is processed by an ExecutorService that has a maximum pool size that matches no of CPUs of the computer. For example, if we have 8-CPU computer then eight folders can (in theory) be processed concurrently, if we have a 16-CPU computer then 16 folders can be processed concurrently. If we only have 1 CPU then we set pool-size to 3, to allow

Let ScheduledThreadPoolExecutor execute tasks on UI thread

穿精又带淫゛_ 提交于 2019-12-24 03:23:36
问题 How can I use a ScheduledThreadPoolExecutor and schedule a task which is always executed on the UI thread? Currently, I do the following mScheduledTask = sBackgroundExecutor.scheduleAtFixedRate(new Runnable() { @Override public void run() { if (mActivity != null) { mActivity.runOnUiThread(new Runnable() { @Override public void run() { // do UI stuff } }); } } }, 0, 200, TimeUnit.MILLISECONDS); This seems unnecessary and hard to read, but I couldn't find anything in the docs. Is it possible or

ThreadPool / Executor on both Runnable and Callable - that can exits automatically java8

拈花ヽ惹草 提交于 2019-12-24 02:09:34
问题 I am trying to use a ThreadPoolExecutor/ExecutorService in my application - it is a static global object. I use: Executors.newScheduledThreadPool(corePoolSize) - but I am having problems with shutting down the executorService. If I don't call shutdown() + awaitTermination() - then my application won't finish -even if all threads are completed. My application has threads being created by other threads - so I can't put a shutdown() anywhere in the code without blocking further threads to be run

Force re-use of thread by CompletableFuture

允我心安 提交于 2019-12-24 00:49:47
问题 I am making critical use of: CompletableFuture .delayedExecutor(1, TimeUnit.MILLISECONDS).execute(() -> {}); From what I have read online, it's common for this to use a new thread for every call. I am wondering if there is a way to re-use a thread instead of creating new threads? Update : I wasn't clear - I want to use CompletableFuture , but I want CompletableFuture to reuse a certain thread, instead of managing its own threads. I see this question: CompletableFuture reuse thread from pool

Why does a SingleThreaded Executor service use 4 cores?

蹲街弑〆低调 提交于 2019-12-24 00:36:01
问题 I have the following code which uses a single-threaded executor service, but running it uses all the 4 cores on my machine (each core around 80% usage in average). The question is why is this happening? And I am not interested here in finding Fibonacci really! public class MainSimpler { static int N=35; static AtomicInteger result = new AtomicInteger(0), pendingTasks = new AtomicInteger(1); static ExecutorService executor; public static void main(String[] args) { executor = Executors

How to get optimal bulk insertion rate in DynamoDb through Executor Framework in Java?

房东的猫 提交于 2019-12-22 23:21:11
问题 I'm doing a POC on Bulk write (around 5.5k items) in local Dynamo DB using DynamoDB SDK for Java. I'm aware that each bulk write cannot have more than 25 write operations, so I am dividing the whole dataset into chunks of 25 items each. Then I'm passing these chunks as callable actions in Executor framework. Still, I'm not having a satisfactory result as the 5.5k records are getting inserted in more than 100 seconds. I'm not sure how else can I optimize this. While creating the table I