我正在尝试Spring 3的@Scheduled注释.这是我的配置(app.xml):
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd
"
>
<context:component-scan base-package="destiny.web"/>
<context:annotation-config/>
// other beans
<task:annotation-driven executor="myExecutor" scheduler="myScheduler"/>
<task:executor id="myExecutor" pool-size="5"/>
<task:scheduler id="myScheduler" pool-size="10"/>
</beans>
Run Code Online (Sandbox Code Playgroud)
这是我的服务类:
@Service
public class ServiceImpl implements Service , Serializable
{
//other injections
@Override
@Transactional
public void timeConsumingJob()
{
try
{
Thread.sleep(10*1000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
@Override
@Scheduled(cron="* * * * * ?")
public void secondly() …Run Code Online (Sandbox Code Playgroud) 我一直在寻找春天引导例如调度任务(https://spring.io/guides/gs/scheduling-tasks/),并通过一些文档阅读(https://javahunter.wordpress.com/2011/05/05/cronscheduler-in-spring /)我看到*和?几乎可互换使用.
例如,该行
@Scheduled(cron = "0 15 10 ? * *")
Run Code Online (Sandbox Code Playgroud)
和
@Scheduled(cron = "0 15 10 * * ?")
Run Code Online (Sandbox Code Playgroud)
做同样的事情.那么*和?之间的区别是什么?
如何在给定时间在Python中运行函数?
例如:
run_it_at(func, '2012-07-17 15:50:00')
Run Code Online (Sandbox Code Playgroud)
它将func在2012-07-17 15:50:00 运行该功能.
我尝试了sched.scheduler,但它没有启动我的功能.
import time as time_module
scheduler = sched.scheduler(time_module.time, time_module.sleep)
t = time_module.strptime('2012-07-17 15:50:00', '%Y-%m-%d %H:%M:%S')
t = time_module.mktime(t)
scheduler_e = scheduler.enterabs(t, 1, self.update, ())
Run Code Online (Sandbox Code Playgroud)
我能做什么?
在java web应用程序(servlets/spring mvc)中,使用tomcat,是否可以运行cron作业类型服务?
例如,每隔15分钟,清除日志数据库.
你能以独立于容器的方式执行此操作,还是必须使用tomcat或其他容器运行?
请指定方法是保证在特定时间运行还是每15分钟运行一次,但如果应用程序循环使用,则可以重置等(如果使用计时器,则为.net中的方式)
我有一个ScheduledThreadPoolExecutor,我用它来安排一个以固定速率运行的任务.我希望任务以指定的延迟运行最多10次,直到它"成功".在那之后,我不希望重试任务.所以基本上我需要停止运行计划任务,当我希望它被停止时,但不关闭ScheduledThreadPoolExecutor.知道我怎么做吗?
这是一些伪代码 -
public class ScheduledThreadPoolExecutorTest
{
public static ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(15); // no multiple instances, just one to serve all requests
class MyTask implements Runnable
{
private int MAX_ATTEMPTS = 10;
public void run()
{
if(++attempt <= MAX_ATTEMPTS)
{
doX();
if(doXSucceeded)
{
//stop retrying the task anymore
}
}
else
{
//couldn't succeed in MAX attempts, don't bother retrying anymore!
}
}
}
public void main(String[] args)
{
executor.scheduleAtFixedRate(new ScheduledThreadPoolExecutorTest().new MyTask(), 0, 5, TimeUnit.SECONDS);
}
}
Run Code Online (Sandbox Code Playgroud) 我已多次阅读此页面,我只是没有看到GWT Timer和Scheduler类之间的一些固有差异.我正在寻找以下各项的用例和适用性:
Timer,Timer::schedule和Timer::scheduleRepeatingScheduler::scheduleDeferredScheduler::scheduleIncrementalIncrementalCommandDeferredCommand这些似乎都在做同样的事情,或多或少,感觉你可以完成所有这些目标.这只是GWT的方式,提供多种方式做同样的事情?如果没有,请帮助我了解每个适当使用的时间和地点.
DBMS_JOB和DBMS_SCHEDULER有什么区别?
from apscheduler.scheduler import Scheduler
import os
class ListHref():
def __init__(self):
print 'In ListHref Class!'
self.name_hrefs = {}
self.name_img = {}
self.path = os.path.dirname(__file__)
print 'Out ListHref Class'
def other_function():...
def job(): #function named job
print 'In job!'
book_href = ListHref()
print 'book_href created!'
if __name__ == "__main__":
sched = Scheduler()
#job() #it's ok if job() called only
sched.daemonic = False #non daemon thread
sched.add_interval_job(job,minutes=0.1)
sched.start()
Run Code Online (Sandbox Code Playgroud)
问题: 如果只调用job()而不是sched,那就没关系所以我很困惑为什么init(self)不能完全调用?什么错了'没有handerls可以找到记录器"apscheduler.scheduler"'? 以上python代码结果:
在工作()
在ListHref类中!
没有找到记录器"apscheduler.scheduler"的handerls
在工作()
在ListHref类中!
在工作()
在ListHref类中!
...(等等)
我已经在多个地方读过Linux的默认调度程序在多核机器上的超线程感知,这意味着如果你有一台具有2个真实内核(4 HT)的机器,它将不会以某种方式将两个忙线程安排到逻辑内核上它们都运行在相同的物理内核上(在许多情况下会导致2倍的性能成本).
但是当我stress -c 2在我的Intel i5-2520M上运行(产生两个线程以在100%CPU上运行)时,它经常将两个线程调度(并保持)到HT核心1和2上,这些核心映射到相同的物理核心.即使系统处于空闲状态.
这也适用于真正的程序(我在stress这里使用它因为它很容易重现),当发生这种情况时,我的程序可以理解地需要两倍的时间来运行.手动设置亲和力与taskset我的程序的修复程序,但我希望HT感知调度程序自己正确地执行此操作.
您可以找到HT->物理核心配置egrep "processor|physical id|core id" /proc/cpuinfo | sed 's/^processor/\nprocessor/g'.
所以我的问题是:为什么调度程序将我的线程放在同一个物理内核上?
笔记:
stress -c),并想知道原因.taskset工具或sched_setaffinity函数.这不是我正在寻找的,我希望调度程序能够自己知道将两个忙线程映射到物理核心并将一个物理核心完全留空并不是一个好主意.stress受益于在不同的物理核心上运行.我正在尝试将Google日历中的日历插件与自定义数据库和代码与C#中的asp.net MVC集成.
它需要像谷歌日历一样处理日历中的日/周/月事件.
我在jquery http://www.webappers.com/2009/08/04/jquery-weekly-calendar-plugin-inspired-by-google-calendar/中找到了类似的插件.但它只显示了周
有人提到这个吗?请建议
scheduler ×10
java ×4
cron ×2
python ×2
spring ×2
asp.net-mvc ×1
c# ×1
crontrigger ×1
dbms-job ×1
fullcalendar ×1
gwt ×1
jquery ×1
linux ×1
oracle ×1
performance ×1
scheduling ×1
spring-3 ×1
time ×1
tomcat ×1