\n\u003Ctask:annotation-driven executor=\"myExecutor\" scheduler=\"myScheduler\" />\n\u003Ctask:executor id=\"myExecutor\" pool-size=\"5\" />\n\u003Ctask:scheduler id=\"myScheduler\" pool-size=\"10\" />\n","xml","",[37,38,39,47,53,59],"code",{"__ignoreMap":35},[40,41,44],"span",{"class":42,"line":43},"line",1,[40,45,46],{},"\u003Cbean id=\"myClass\" class=\"my.project.path.myClass\" />\n",[40,48,50],{"class":42,"line":49},2,[40,51,52],{},"\u003Ctask:annotation-driven executor=\"myExecutor\" scheduler=\"myScheduler\" />\n",[40,54,56],{"class":42,"line":55},3,[40,57,58],{},"\u003Ctask:executor id=\"myExecutor\" pool-size=\"5\" />\n",[40,60,62],{"class":42,"line":61},4,[40,63,64],{},"\u003Ctask:scheduler id=\"myScheduler\" pool-size=\"10\" />\n",[22,66,68],{"id":67},"the-scheduled-annotation","The @Scheduled annotation",[18,70,71],{},"With the @Scheduled annotation you can execute your method as a cron job. Using this annotation requires that the method\nto be scheduled must be of type void and must not expect any arguments. The following examples show you how to use the\n@Scheduled annotation.",[18,73,74],{},"If you want periodic scheduling you can use the property fixedRate. In this example the method would be executed every\n42 seconds.",[30,76,80],{"className":77,"code":78,"language":79,"meta":35,"style":35},"language-java shiki shiki-themes github-light github-dark","@Scheduled(fixedRate = 42000)\npublic void execute() {\n // do something\n}\n","java",[37,81,82,87,92,97],{"__ignoreMap":35},[40,83,84],{"class":42,"line":43},[40,85,86],{},"@Scheduled(fixedRate = 42000)\n",[40,88,89],{"class":42,"line":49},[40,90,91],{},"public void execute() {\n",[40,93,94],{"class":42,"line":55},[40,95,96],{}," // do something\n",[40,98,99],{"class":42,"line":61},[40,100,101],{},"}\n",[18,103,104],{},"If you prefer cron expressions you can use them either. The following example is analogue to the example above only\nusing cron expressions. The annotated method would be executed each full minute and every 7 seconds.",[30,106,108],{"className":77,"code":107,"language":79,"meta":35,"style":35},"@Scheduled(cron = \"*/7 * * * * *\")\npublic void execute() {\n // do something\n}\n",[37,109,110,115,119,123],{"__ignoreMap":35},[40,111,112],{"class":42,"line":43},[40,113,114],{},"@Scheduled(cron = \"*/7 * * * * *\")\n",[40,116,117],{"class":42,"line":49},[40,118,91],{},[40,120,121],{"class":42,"line":55},[40,122,96],{},[40,124,125],{"class":42,"line":61},[40,126,101],{},[18,128,129],{},"Without question you have much more possibilities with cron expressions than with periodic scheduling. In this example\nyour method would be executed every weekday (Monday to Friday) on 9.45 am.",[30,131,133],{"className":77,"code":132,"language":79,"meta":35,"style":35},"@Scheduled(cron = \"0 45 9 * * MON-FRI\")\npublic void execute() {\n // do something\n}\n",[37,134,135,140,144,148],{"__ignoreMap":35},[40,136,137],{"class":42,"line":43},[40,138,139],{},"@Scheduled(cron = \"0 45 9 * * MON-FRI\")\n",[40,141,142],{"class":42,"line":49},[40,143,91],{},[40,145,146],{"class":42,"line":55},[40,147,96],{},[40,149,150],{"class":42,"line":61},[40,151,101],{},[18,153,154],{},"A pretty cool feature is that you even can use placeholders for your cron expression which are resolved against the\nconfigured property-placeholder.",[30,156,158],{"className":77,"code":157,"language":79,"meta":35,"style":35},"@Scheduled(cron = \"${myclass.cron.execute.sth}\")\npublic void execute() {\n // do something\n}\n",[37,159,160,165,169,173],{"__ignoreMap":35},[40,161,162],{"class":42,"line":43},[40,163,164],{},"@Scheduled(cron = \"${myclass.cron.execute.sth}\")\n",[40,166,167],{"class":42,"line":49},[40,168,91],{},[40,170,171],{"class":42,"line":55},[40,172,96],{},[40,174,175],{"class":42,"line":61},[40,176,101],{},[18,178,179],{},"Define where the properties are loaded from within your application context:",[30,181,183],{"className":32,"code":182,"language":34,"meta":35,"style":35},"\u003Ccontext:property-placeholder location=\"classpath:application.properties\"/>\n",[37,184,185],{"__ignoreMap":35},[40,186,187],{"class":42,"line":43},[40,188,182],{},[18,190,191],{},"Then the properties are loaded from the file which contains your cron-expressions like this:",[30,193,197],{"className":194,"code":195,"language":196,"meta":35,"style":35},"language-plaintext shiki shiki-themes github-light github-dark","myclass.cron.execute.sth=0 45 9 * * MON-FRI\n","plaintext",[37,198,199],{"__ignoreMap":35},[40,200,201],{"class":42,"line":43},[40,202,195],{},[22,204,206],{"id":205},"the-async-annotation","The @Async annotation",[18,208,209],{},"The @Async annotation allows you to invoke your method asynchronously. The execution of the method will occur in a task\nthat has been submitted to the TaskExecutor defined in your application context. Contrary to the methods annotated with\nthe @Scheduled annotations the methods you annotate with @Async may be of other type than void and can expect arguments.",[18,211,212],{},"This is a simple example of a @Async annotated method without a return value.",[30,214,216],{"className":77,"code":215,"language":79,"meta":35,"style":35},"@Async\nvoid execute(String string) {\n // do something asynchronously\n}\n",[37,217,218,223,228,233],{"__ignoreMap":35},[40,219,220],{"class":42,"line":43},[40,221,222],{},"@Async\n",[40,224,225],{"class":42,"line":49},[40,226,227],{},"void execute(String string) {\n",[40,229,230],{"class":42,"line":55},[40,231,232],{}," // do something asynchronously\n",[40,234,235],{"class":42,"line":61},[40,236,101],{},[18,238,239],{},"Like mentioned above your @Async annotated method may have a return value. However this return value must be of type\nFuture. This means that first the other tasks are performed and then is called get() on that Future.",[30,241,243],{"className":77,"code":242,"language":79,"meta":35,"style":35},"@Async\nFuture\u003CString> execute(String string) {\n // do something asynchronously\n}\n",[37,244,245,249,254,258],{"__ignoreMap":35},[40,246,247],{"class":42,"line":43},[40,248,222],{},[40,250,251],{"class":42,"line":49},[40,252,253],{},"Future\u003CString> execute(String string) {\n",[40,255,256],{"class":42,"line":55},[40,257,232],{},[40,259,260],{"class":42,"line":61},[40,261,101],{},[22,263,265],{"id":264},"further-information","Further information",[18,267,268,269],{},"Have a look at\nthe ",[270,271,275],"a",{"href":272,"rel":273},"http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/htmlsingle/spring-framework-reference.html#scheduling",[274],"nofollow","Spring Framework Reference Documentation",[277,278,279],"style",{},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":35,"searchDepth":49,"depth":49,"links":281},[282,283,284,285],{"id":24,"depth":55,"text":25},{"id":67,"depth":55,"text":68},{"id":205,"depth":55,"text":206},{"id":264,"depth":55,"text":265},[287,288],"azubi-blog","developer-blog","2012-06-13T15:49:15","You want to execute cron jobs or call your methods asynchronously? Thanks to Spring’s annotation support for scheduling\\nand asynchronous execution you can achieve this in a few minutes.","md","https://synyx.de/blog/scheduling-and-asynchronous-execution-with-spring/",{},true,"/blog/scheduling-and-asynchronous-execution-with-spring",{"title":7,"description":20},"blog/scheduling-and-asynchronous-execution-with-spring",[299,300,301,302,303,304],"async","scheduled","asynchronous","scheduling","spring","spring-annotations","You want to execute cron jobs or call your methods asynchronously? Thanks to Spring’s annotation support for scheduling and asynchronous execution you can achieve this in a few minutes. Some…","fzW4lb1yw0kNbXB83aAmQzrzjrslpT-gtiBvUzbdR7Q",[308,311,314,317,320,323,326,329,332,334,337,340,343,346,349,352,355,358,361,364,367,370,372,375,378,381,384,386,389,392,395,398,401,404,407,410,413,416,419,422,425,428,431,434,437,440,443,446,449,452,455,458,461,464,467,470,473,476,479,482,485,488,491,494,497,500,503,506,509,512,515,518,521,524,527,530,533,536,539,542,545,548,551,554,557,560,563,566,569,572,575,578,581,584,587,590,593,596,599,601,604,607,610,613,615,618,621,624,627,630,633,636,639,642,645,648,651,654,657,660,663,666,669,672,675,678,681,684,687,690,692,695,698,701,704,707,710,713,716,719,722,725],{"slug":309,"name":310},"abel","Jennifer Abel",{"slug":312,"name":313},"allmendinger","Otto Allmendinger",{"slug":315,"name":316},"antony","Ben Antony",{"slug":318,"name":319},"arrasz","Joachim Arrasz",{"slug":321,"name":322},"bauer","David Bauer",{"slug":324,"name":325},"bechtold","Janine Bechtold",{"slug":327,"name":328},"boersig","Jasmin Börsig",{"slug":330,"name":331},"buch","Fabian Buch",{"slug":9,"name":333},"Aljona Buchloh",{"slug":335,"name":336},"burgard","Julia Burgard",{"slug":338,"name":339},"caspar-schwedes","Caspar Schwedes",{"slug":341,"name":342},"christina-schmitt","Christina Schmitt",{"slug":344,"name":345},"clausen","Michael Clausen",{"slug":347,"name":348},"contargo_poetzsch","Thomas Pötzsch",{"slug":350,"name":351},"damrath","Sebastian Damrath",{"slug":353,"name":354},"daniel","Markus Daniel",{"slug":356,"name":357},"dasch","Julia Dasch",{"slug":359,"name":360},"denman","Joffrey Denman",{"slug":362,"name":363},"dfuchs","Daniel Fuchs",{"slug":365,"name":366},"dobler","Max Dobler",{"slug":368,"name":369},"dobriakov","Vladimir Dobriakov",{"slug":371,"name":371},"dreiqbik",{"slug":373,"name":374},"dschaefer","Denise Schäfer",{"slug":376,"name":377},"dschneider","Dominik Schneider",{"slug":379,"name":380},"duerlich","Isabell Duerlich",{"slug":382,"name":383},"dutkowski","Bernd Dutkowski",{"slug":385,"name":385},"eifler",{"slug":387,"name":388},"essig","Tim Essig",{"slug":390,"name":391},"ferstl","Maximilian Ferstl",{"slug":393,"name":394},"fey","Prisca Fey",{"slug":396,"name":397},"frank","Leonard Frank",{"slug":399,"name":400},"franke","Arnold Franke",{"slug":402,"name":403},"frischer","Nicolette Rudmann",{"slug":405,"name":406},"fuchs","Petra Fuchs",{"slug":408,"name":409},"gari","Sarah Gari",{"slug":411,"name":412},"gast","Gast",{"slug":414,"name":415},"graf","Johannes Graf",{"slug":417,"name":418},"grammlich","Daniela Grammlich",{"slug":420,"name":421},"guthardt","Sabrina Guthardt",{"slug":423,"name":424},"haeussler","Johannes Häussler",{"slug":426,"name":427},"hammann","Daniel Hammann",{"slug":429,"name":430},"heetel","Julian Heetel",{"slug":432,"name":433},"heft","Florian Heft",{"slug":435,"name":436},"heib","Sebastian Heib",{"slug":438,"name":439},"heisler","Ida Heisler",{"slug":441,"name":442},"helm","Patrick Helm",{"slug":444,"name":445},"herbold","Michael Herbold",{"slug":447,"name":448},"hofmann","Peter Hofmann",{"slug":450,"name":451},"hopf","Florian Hopf",{"slug":453,"name":454},"jaud","Alina Jaud",{"slug":456,"name":457},"jayasinghe","Robin De Silva Jayasinghe",{"slug":459,"name":460},"jbuch","Jonathan Buch",{"slug":462,"name":463},"junghanss","Gitta Junghanß",{"slug":465,"name":466},"kadyietska","Khrystyna Kadyietska",{"slug":468,"name":469},"kannegiesser","Marc Kannegiesser",{"slug":471,"name":472},"karoly","Robert Károly",{"slug":474,"name":475},"karrasz","Katja Arrasz-Schepanski",{"slug":477,"name":478},"kaufmann","Florian Kaufmann",{"slug":480,"name":481},"kesler","Mike Kesler",{"slug":483,"name":484},"kirchgaessner","Bettina Kirchgäßner",{"slug":486,"name":487},"klem","Yannic Klem",{"slug":489,"name":490},"klenk","Timo Klenk",{"slug":492,"name":493},"knell","Tobias Knell",{"slug":495,"name":496},"knoll","Anna-Lena Knoll",{"slug":498,"name":499},"knorre","Matthias Knorre",{"slug":501,"name":502},"koenig","Melanie König",{"slug":504,"name":505},"kraft","Thomas Kraft",{"slug":507,"name":508},"krupicka","Florian Krupicka",{"slug":510,"name":511},"kuehn","Christian Kühn",{"slug":513,"name":514},"lange","Christian Lange",{"slug":516,"name":517},"larrasz","Luca Arrasz",{"slug":519,"name":520},"leist","Sascha Leist",{"slug":522,"name":523},"lihs","Michael Lihs",{"slug":525,"name":526},"linsin","David Linsin",{"slug":528,"name":529},"maniyar","Christian Maniyar",{"slug":531,"name":532},"martin","Björnie",{"slug":534,"name":535},"martin-koch","Martin Koch",{"slug":537,"name":538},"matt","Tobias Matt",{"slug":540,"name":541},"mennerich","Christian Mennerich",{"slug":543,"name":544},"menz","Alexander Menz",{"slug":546,"name":547},"meseck","Frederick Meseck",{"slug":549,"name":550},"messner","Oliver Messner",{"slug":552,"name":553},"michael-ploed","Michael Plöd",{"slug":555,"name":556},"mies","Marius Mies",{"slug":558,"name":559},"mihai","Alina Mihai",{"slug":561,"name":562},"moeller","Jörg Möller",{"slug":564,"name":565},"mohr","Rebecca Mohr",{"slug":567,"name":568},"moretti","David Moretti",{"slug":570,"name":571},"mueller","Sven Müller",{"slug":573,"name":574},"muessig","Alexander Müssig",{"slug":576,"name":577},"neupokoev","Grigory Neupokoev",{"slug":579,"name":580},"nussbaecher","Carmen Nussbächer",{"slug":582,"name":583},"ochs","Pascal Ochs",{"slug":585,"name":586},"oelhoff","Jan Oelhoff",{"slug":588,"name":589},"oengel","Yasin Öngel",{"slug":591,"name":592},"oezsoy","Enis Özsoy",{"slug":594,"name":595},"posch","Maya Posch",{"slug":597,"name":598},"ralfmueller","Ralf Müller",{"slug":600,"name":600},"redakteur",{"slug":602,"name":603},"reich","Michael Reich",{"slug":605,"name":606},"reinhard","Karl-Ludwig Reinhard",{"slug":608,"name":609},"rmueller","Rebecca Müller",{"slug":611,"name":612},"rosum","Jan Rosum",{"slug":614,"name":614},"rueckert",{"slug":616,"name":617},"ruessel","Sascha Rüssel",{"slug":619,"name":620},"sauter","Moritz Sauter",{"slug":622,"name":623},"schaefer","Julian Schäfer",{"slug":625,"name":626},"scherer","Petra Scherer",{"slug":628,"name":629},"schlicht","Anne Schlicht",{"slug":631,"name":632},"schmidt","Jürgen Schmidt",{"slug":634,"name":635},"schneider","Tobias Schneider",{"slug":637,"name":638},"seber","Benjamin Seber",{"slug":640,"name":641},"sommer","Marc Sommer",{"slug":643,"name":644},"speaker-fels","Jakob Fels",{"slug":646,"name":647},"speaker-gierke","Oliver Gierke",{"slug":649,"name":650},"speaker-krupa","Malte Krupa",{"slug":652,"name":653},"speaker-mader","Jochen Mader",{"slug":655,"name":656},"speaker-meusel","Tim Meusel",{"slug":658,"name":659},"speaker-milke","Oliver Milke",{"slug":661,"name":662},"speaker-paluch","Mark Paluch",{"slug":664,"name":665},"speaker-schad","Jörg Schad",{"slug":667,"name":668},"speaker-schalanda","Jochen Schalanda",{"slug":670,"name":671},"speaker-schauder","Jens Schauder",{"slug":673,"name":674},"speaker-unterstein","Johannes Unterstein",{"slug":676,"name":677},"speaker-wolff","Eberhard Wolff",{"slug":679,"name":680},"speaker-zoerner","Stefan Zörner",{"slug":682,"name":683},"stefan-belger","Stefan Belger",{"slug":685,"name":686},"steinegger","Roland Steinegger",{"slug":688,"name":689},"stern","sternchen synyx",{"slug":691,"name":691},"synyx",{"slug":693,"name":694},"szulc","Mateusz Szulc",{"slug":696,"name":697},"tamara","Tamara Tunczinger",{"slug":699,"name":700},"theuer","Tobias Theuer",{"slug":702,"name":703},"thieme","Sandra Thieme",{"slug":705,"name":706},"thies-clasen","Marudor",{"slug":708,"name":709},"toernstroem","Olle Törnström",{"slug":711,"name":712},"ullinger","Max Ullinger",{"slug":714,"name":715},"ulrich","Stephan Ulrich",{"slug":717,"name":718},"wagner","Stefan Wagner",{"slug":720,"name":721},"weigel","Andreas Weigel",{"slug":723,"name":724},"werner","Fabian Werner",{"slug":726,"name":727},"wolke","Sören Wolke",["Reactive",729],{"$scookieConsent":730,"$ssite-config":732},{"functional":731,"analytics":731},false,{"_priority":733,"env":737,"name":738,"url":739},{"name":734,"env":735,"url":736},-10,-15,0,"production","nuxt-app","https://synyx.de",["Set"],["ShallowReactive",742],{"category-spring-annotations":-1,"authors":-1},"/blog/tags/spring-annotations"]