java


How to catch any uncaught exception in a spring application? [duplicate]


How to customize the exception handling for "#Scheduled" annotation from spring ?
I have cron jobs which will be triggered in the server (Tomcat 6) and when any exceptions occur I need to do some handling.
Spring version 3.2
Tomcat Server 6
You could implement and register an ErrorHandler for the ThreadPoolTaskScheduler that is used for your scheduling annotations.
<task:annotation-driven scheduler="yourThreadPoolTaskScheduler" />
<bean id="yourThreadPoolTaskScheduler" class="org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler">
<property name="poolSize" value="5" />
<property name="errorHandler" ref="yourScheduledTaskErrorHandler" />
</bean>
<bean id="yourScheduledTaskErrorHandler"
class="com.example.YourScheduledTaskErrorHandler"/>
Why not wrap your business logic and do a simple try catch in your #schedule method. Then you can log or take whatever action is necessary for failure cases.
#Scheduled(cron = "${schedulerRate}")
public void scheduledJob() {
try {
businessLogicService.doBusinessLogic();
} catch (Exception e) {
log.error(e);
}
}

Related Links

adding 2D array rows with Java
Hiding a JButton
How does Codename One work for device specific features?
“java.lang.OutOfMemoryError: Java heap space” when starting WSO2 Enterprise Mobility Manager
MultitClient Server - Allowing Constant communication
MOXy unmarshalling not tolerating whitespace before dateTime
Why does Rect(10,10,20,20) NOT intersect with Rect(20,20,30,30)
AspectJ exchange data between Advice and JoinPoint
tomcat changes 404 status into 403 for http delete
Spring Json property mapping an array of Strings to a field in an array of Objects
What is the difference between Scheduler and Timer in GWT?
Scheduling Threads and Synchronized Methods
Maven executable jar packaging vs Maven exec with Jackson not working
Can't load data to TableView
Most efficient way to sort by multiple fields in Java
Is it possible to map Spring components through annotations using enums?

Categories

HOME
pdf
cookies
deezer
push-notification
plot
office365api
dot
tesseract
mean-stack
q
spring-jdbc
angular-ui-bootstrap
serverspec
gitpitch
google-translate
vifm
reveal.js
export-to-csv
circular-dependency
percona
systemc
highlight.js
ab-testing
emulator
visjs
paging
ml
riot.js
web-sql
realex-payments-api
dxf
virtualdub
uninstall
buck
librato
google-rich-snippets
uisplitview
winrt-xaml-toolkit
mozilla
language-concepts
normal-distribution
mpmediaquery
fusionpbx
main
serve
web-mining
dynamics-crm-2013
code-search-engine
c11
mesos-chronos
optix
android-mediaprojection
fakeiteasy
keydown
hibernate-tools
fancybox-2
aurelia-validation
brightcove
worker-thread
snmptrapd
r-forge
gcsfuse
dwscript
redundancy
vtigercrm
migradoc
bluegiga
ios4
sdhc
endeca-workbench
thredds
wordml
libressl
jqgrid-formatter
pundit
method-parameters
sailfish-os
knuth
phalanger
terminfo
jquery-layout
ember-charts
intentservice
ivyde
sitemesh
apc
chronoforms
http-unit
tinn-r
selected
simba
path-separator
isnullorempty
newtonscript
tridion-worldserver
online-compilation
libc++
doh
winbugs14
getresponsestream
simpletest
windows-live-messenger
misv

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App