Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7786115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:21:51+00:00 2026-06-01T20:21:51+00:00

Given: Method in a @Stateless EJB, JTA Mysql data source and a list of

  • 0

Given: Method in a @Stateless EJB, JTA Mysql data source and a list of about 5000 entities which I’m trying to persist in a cycle :

List<MyObj> objList = entityManager.createNamedQuery("Q1", MyObj.class).getResultList();
for(MyObj obj : objList) {
  long start_time = Calendar.getInstance().getTimeInMillis();
  entityManager.persist(obj);
  long end_time = Calendar.getInstance().getTimeInMillis();
  logger.info("Object saved in " + (end_time - start_time) + "ms");
}
entityManager.close();

Log shows gradually decreasing performance from 15ms up to 180ms save time per entity. I believe Mysql sever settings are far beyond the needs of this task – it shows insignificant increase in CPU and I/O operations. Flushing EntityManager after each update has no effect.

What could be the reason for such performance decrease? Please point me in the right direction.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T20:21:52+00:00Added an answer on June 1, 2026 at 8:21 pm

    It looks like slowdown is caused by large number of entities in persistence context (i.e. in its session cache). flush doesn’t help here because it doesn’t remove entities from persistence context.

    If you need to process a large number of entities using a single persistence context it’s recommended to clear the context with clear() periodically.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can I find out from which class a given method's implementation is inherited? e.g.
Is it possible to retrieve from inside a given method any information about the
I am learning EJB and I am trying to execute the Helloworld example given
Given a method.. public ActionResult Method() { // program logic if(condition) { // external
It seems that the following is a common method given in many tutorials on
Given the following method signature, why is it when a parameter is explicitly named
Given that Date has a method called after(Date) and Timestamp has a method the
Given the following two ways of defining a class method in Ruby: class Foo
Given two dates, what is the best method to calculate the number of days
Given a string s , what is the fastest method to generate a set

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.