I am using JPA to persist records to Oracle database. Everytime I run the application, it goes to a particular directory and parse every single file in there and load into tables. Usually there are thousands of files to be processed.
An new EntityManagerFactory is created every time I process a file and when the record is inserted. Therefore, the EMF is opened thousands of times every run. When I am debugging it I discovered creation of EMF is the most time consuming step which takes more than 90% of the run time. On average creating a new EMF takes about 2-3 seconds. Maybe I should just open EMF connection once at the beginning of the application before iteration of files starts? Is it good practice to have EMF open the whole time?