When we finished performing the specified business need to adjust the timing of the task to refresh the data, then the timing of the task is there, rewrite the timing logic is too cumbersome task in the project code, so get registered xxl bean container directly from the spring and then we get regular tasks required to perform bean execute method
WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext();
if (wac == null)
{
return;
}
// get JobHandler notes from the spring of bean map
Map<String, Object> serviceBeanMap = wac.getBeansWithAnnotation(JobHandler.class);
if (serviceBeanMap != null && serviceBeanMap.size() > 0)
{
for (Object serviceBean : serviceBeanMap.values())
{
// determine whether IJobHandler
if (serviceBean instanceof IJobHandler)
{
String name = serviceBean.getClass().getAnnotation(JobHandler.class).value();
if ("itemBalanceJobHandler".equals(name))
{
try
{
((IJobHandler) serviceBean).execute(null);
}
catch (Exception e)
{
logger.error ( "refresh sub-account balance abnormal" + e);
}
}
}
}
}