I create a very simple SpringBoot Application accessing Oracle database with one table by JPA. I create a war file and repeatedly deploy and undeploy in a tomcat server. After serveral times there is MetaSpace OOM.
Environment:
a. OS : Ubuntu 22.04.3
b. JVM : Oracle Java 11.0.18 and Oracle java 17.0.17 (tested both)
c. Tomcat : 9.0.75
d. SpringBoot : 2.7.5
e. Oracle : version 19c
f. Oracle jdbc : com.oracle.database.jdbc:ojdbc11:23.2.0.0\
Source code:
Policy.java:
Getter
@Setter
@Entity
@Table(name = "policy_m")
public class Policy {
@Column(name = "policy_agreement_id")
private Long policyAgreementId;
@Id
@Column(name = "policy_num")
private String policyNum;
}
PolicyRepository.java:
@Repository
public interface PolicyRepository extends JpaRepository<Policy, String> {
@Query(value = "select * from policy_m where policy_num = :policyNum", nativeQuery = true)
Policy getPolicyByPolicyNum(@Param("policyNum") String policyNum);
}
PolicyServiceImpl.java:
@Service
public class PolicyServiceImpl implements PolicyService {
@Autowired
private PolicyRepository policyRepository;
public Policy getPolicyByPolicyNum(String policyNum) {
return policyRepository.getPolicyByPolicyNum(policyNum);
}
}
DemoController.java:
@RestController
public class DemoController {
@Autowired
private PolicyService policyService;
@GetMapping("/{policyNum}")
public Policy database(@PathVariable("policyNum") String policyNum) {
return policyService.getPolicyByPolicyNum(policyNum);
}
}
Steps to reproduce:
- prepare the war file
- deploy to the tomcat through the admin console
- undeploy the application through the admin console
- repeat step 2 - 3 until it throws MetaSpace OOM
The VisualVM shows the chart as attached
At the plateau at the right hand side, the tomcat actually already hanged.