我有一个 spring boot 应用程序,它使用 @Scheduled 每 500 微秒从数据库中获取一次数据。我的一个 friend 劝阻我说这是一种渎职行为。这是我的示例代码:
@Scheduled(fixedRate = 500)
@Override
public void sync() {
departments.setAll((Collection<? extends Department>) departmentRepository.findAll());
sections.setAll((Collection<? extends Section>) sectionRepository.findAll());
positions.setAll((Collection<? extends Position>) positionRepository.findAll());
}
我的应用程序运行良好,但我唯一担心的是这是一个好习惯吗?有什么优点和缺点?
最佳答案
非常糟糕的做法,
你需要找到另一种方式让你的用户看到更新而不是这样做,如果 30 分钟没有更新,你的数据库将保持同步,如果你尝试使用触发器之类的东西会更好。
关于java - 每半秒同步一次数据库是个好主意吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51581109/