scheduling

How to stop a task in ScheduledThreadPoolExecutor once I think it's completed

时间秒杀一切 提交于 2019-12-02 20:33:18
I have a ScheduledThreadPoolExecutor with which I schedule a task to run at a fixed rate. I want the task to be running with a specified delay for a maximum of say 10 times until it "succeeds". After that, I will not want the task to be retried. So basically I'll need to stop running the scheduled task when I want it to be stopped, but without shutting down the ScheduledThreadPoolExecutor. Any idea how I'd do that? Here's some pseudocode - public class ScheduledThreadPoolExecutorTest { public static ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(15); // no multiple

Heuristic algorithm for load balancing among threads

梦想的初衷 提交于 2019-12-02 19:43:07
I'm working on a multi-threaded program where I have a number of worker threads performing tasks of unequal length. I want to load-balance the tasks to ensure that they do roughly the same amount of work. For each task T i I have a number c i which provides a good approximation to the amount of work that is required for that task. I'm looking for an efficient (O(N) N = number of tasks or better) algorithm which will give me "roughly" a good load balance given the values of c i . It doesn't have to be optimal, but I would like to be able to have some theoretical bounds on how bad the resulting

Job queue optimization algorithms

一笑奈何 提交于 2019-12-02 19:38:51
We have an application that requires assignment of jobs to resources. The resources have a number of attributes that define their suitability to a particular job -- some are preferences, some are hard constraints (all of the membership variety, e.g. "resource A is suited to jobs with color X, Y, or Z". Resources have a cost associated with them (the duration they spend on-line). We have the ability to recruit resources -- this takes a variable amount of time. We can recruit for a fixed interval of time. To give an idea of scale: There will be about 20 resources at any given time, 100

How to run processes piped with bash on multiple cores?

与世无争的帅哥 提交于 2019-12-02 19:38:33
I have a simple bash script that pipes output of one process to another. Namely:. dostuff | filterstuff It happens that on my Linux system (openSUSE if it matters, kernel 2.6.27) these both processes run on a single core. However, running different processes on different cores is a default policy that doesn't happen to trigger in this case. What component of the system is responsible for that and what should I do to utilize multicore feature? Note that there's no such problem on 2.6.30 kernel. Clarification : Having followed Dennis Williamson 's advice, I made sure with top program, that piped

How to schedule a task in Tomcat

僤鯓⒐⒋嵵緔 提交于 2019-12-02 19:14:33
I have a web application deployed in Tomcat. I have a set of code in it, that checks database for certain data and then sends a mail to users depending on that data. Can somebody suggest how to schedule this in Tomcat. Actually, the best way to schedule task in Tomcat is to use ScheduledExecutorService. TimeTask should not be used in J2E applications, this is not a good practice. Example with the right way : create a package different that you controller one (servlet package), and create a new java class on this new package as example : // your package import java.util.concurrent.Executors;

Run a powershell script in the background once per minute

情到浓时终转凉″ 提交于 2019-12-02 18:34:12
I want a powershell script to be run once per minute in the background. No window may appear. How do I do it? Use the Windows Task Scheduler and run your script like this: powershell -File myScript.ps1 -WindowStyle Hidden Furthermore create the script that it runs under a specific user account and not only when that user is logged on . Otherwise you'll see a console window. Perhaps this scenario will do. We do not start PowerShell executable every minute (this is expensive, BTW). Instead, we start it once by calling an extra script that calls the worker script once a minute (or actually waits

Comparing DateTime structs to find free slots

此生再无相见时 提交于 2019-12-02 18:11:17
I would like to search through the events of all of the users in a list and retrieve all times where every user is free of 30mins or greater between 7AM-7PM. There is a catch however, if a method is marked as 'recurring', ie the bit recurring is set to 1, then that event recurs for a period of 52 weeks after its beginning (so the time is not available). Retrieval of these events are taken care of in a stored procedure. My code so far is below. Am I going about writing this procedure the right way? I'm not really sure how to proceed to get the function to return as I would like. Would anyone be

Schedule timer to be executed once a month - C#

百般思念 提交于 2019-12-02 17:54:40
问题 I need to transfer some data from SQL Server to MySQL, once a month. I have already done this transfer stuff, but I don't know (and I have not found out on the internet) how to set a timer that executes this transfer a specific day every month. I don't want just to set a timer interval in milliseconds because the number of days vary from one month to another. Any help is appreciated... 回答1: You could use the Windows Task Scheduler for this kind of work. Look here for command line options of

What context does the scheduler code run in?

拥有回忆 提交于 2019-12-02 17:43:08
There are two cases where the scheduler code schedule() is invoked- When a process voluntarily calls schedule() Timer interrupt calls schedule() In case 2, I think schedule() runs in interrupt context, but what about the first case? Does it run in the context of the process which invoked it? Also are there any more scenarios which invoke schedule() ? schedule() always runs in process context. In the second case, when it is initiated by a timer interrupt, it is in the return path back from the kernel to the interrupted process where schedule() is called. __schedule() is the main scheduler

Spring Scheduling: @Scheduled vs Quartz

随声附和 提交于 2019-12-02 17:25:25
I'm reading the Spring 3.0 doc s regarding scheduling. I'm leaning towards Spring's JobDetailBean for Quartz. However, the @Scheduled annotation has captured my eye. It appears this is another way of scheduling task using the Spring Framework. Based on the docs, Spring provides three way of scheduling: @Scheduled Via Quartz Via JDK Timer I have no interest in the JDK Timer. Why should I choose @Scheduled over Quartz? (When I mention Quartz I mean using Spring's bean wrapper for Quartz). Let's say my use case is complex enough that I will be communicating to a third-party web service to import