我有一个似乎使用过多内存的应用程序。我已经尝试寻找源了一段时间。但是仍然没有运气。
我已经阅读了几篇文章,这些文章指出JPA是Spring Boot的某些内存问题的元凶。我只有一个存储库,所以我无法想象这是问题所在。
@Repository
public interface WordRepository extends JpaRepository<Word, Long> {
@Query("SELECT w FROM Word w WHERE w.value IN (:words)")
List<Word> findAllIn(@Param("words") List<String> words);
Word findFirstByValue(String value);
@Transactional
Long removeByValue(String value);
Page<Word> findAllByCategory(Pageable pageable, String category);
}
Run Code Online (Sandbox Code Playgroud)
我还有另一个类,可以用来删除表。我无法使用JPA(我知道)执行此操作,因此我获得了持久性对象并使用它来截断表。
@Service
public class WordRepositoryHelper {
@PersistenceContext(unitName = "default")
private EntityManager entityManager;
@Transactional
public int truncateWordTable() {
final String sql = "truncate table word";
entityManager.createNativeQuery(sql).executeUpdate();
return 1;
}
}
Run Code Online (Sandbox Code Playgroud)
我在这里使用它们。
@Service
@SuppressWarnings("deprecation")
public class CSVResourceService implements ResourceService {
@Autowired
private WordRepository wordRepository;
@Autowired
private WordRepositoryHelper wordRepositoryHelper;
private static final String HEADER_ID = "id";
private static final String HEADER_VALUE = "value";
private static final String HEADER_CATEGORY = "category";
@Override
public Boolean save(MultipartFile file, Boolean replace) throws Exception {
// some other code
if (replace) {
wordRepositoryHelper.truncateWordTable();
}
//some other code
}
}
Run Code Online (Sandbox Code Playgroud)
关于该问题或建议的任何指导。
小智 6
非常感谢评论中的所有建议。您可能已经猜到这是我第一次处理内存问题,并且由于它是在生产环境中发生的,因此我感到有些恐慌。
因此,真正的问题不是真正的JPA。它更像是问题和问题的结合。就像一些评论所建议的那样,我的记忆力问题应归咎于很多候选人:
这是我解决问题的方法:


-Xms256m -Xmx512m在执行罐子时使用,这样您就可以缩小范围并查看应归咎于谁。同样,它将限制服务器中的资源。就是这样,我认为我现在很好。
感谢所有人的帮助。
| 归档时间: |
|
| 查看次数: |
5311 次 |
| 最近记录: |