我在spring应用程序中有一个预定的方法。在这种方法中,我尝试通过uuid删除实体,并且此操作已运行很长时间。当我尝试重新启动应用程序时,我看到查询仍在执行中(在应用程序停止后),当应用程序尝试再次启动时,我的liquibase迁移脚本(例如,如果该表上不存在,则创建索引)无法执行(处于挂起状态)。 怎么了?停止应用程序时如何停止查询执行?要重新启动应用程序,我现在要立即重新启动postgresql db服务器(这不是我想要的)。
@Component
public class CleanMyEntitiesJob {
@Autowired
private MyEntityService myEntityService;
@Scheduled(fixedDelay = 10000)
public void clean() {
List<String> entitiesToDelete = myEntityService.getEntitiesToDelete();
if (CollectionUtils.isNotEmpty(entitiesToDelete)) {
entitiesToDelete.stream().forEach(uuid -> {
cameraService.delete(uuid);
});
}
}
}
@Service
public class MyEntityServiceImpl implements MyEntityService {
@Autowired
private MyEntityRepository myEntityRepository;
@Override
public void delete(String uuid) {
myEntityRepository.delete(uuid);
}
@Override
public void getEntitiesToDelete(String uuid) {
....
}
}
@Service
public class MyEntityRepository implements extends JpaRepository<MyEntity, String> {
@Modifying
@Query("DELETE FROM MyEntity WHERE uuid = ?1")
void clean(String uuid);
}