In the data synchronization mode, for some can not monitor data changes or data changes too often, the way I used the timer update cached data, for example:
@Scheduled(fixedRate = 1000) public void getCurrentDate() { List<Map<String, Object>> instanceList = assemblyService.getInstanceList(); for (Map<String, Object> instance : instanceList) { String url = DataUtil.objToString(instance.get("homePageUrl")); String instanceId = DataUtil.objToString(instance.get("instanceId")); insert(url, instanceId); } }
The drawbacks is that this way, thread blocking easily occurs, so the way to the long link:
private static void run() { Date date =new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); System.out.println("hahhaha"+sdf.format(date)); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace (); }finally { run(); } } public static void main(String[] args) { run(); }
The difference between these two methods is that:
(1) The first way: When the process is blocked, one second will still be executed once the method.
(2) The second way: When the process is blocked, the program will wait for execution after the execution once in every second.
So using a long way connected to solve congestion problems