EJB method takes longer to return after each call

I observe unusual behavior, and I would like to understand what is happening.

Imagine a simple setup.

First, I have a bezelless bean that just returns something:

@Stateless public class SimpleService{ private Map<String, String> map; @PostConstruct public init(){ map = new HashMap<>(); } public Map<String,String> getMap(){ return map; } } 

Then I have another stateless bean that does some processing

 @Stateless public class ProcessService{ private static final Logger log = LoggerFactory.getLogger(ProcessService.class); private static final int MAX = 2000; @Inject private SimpleService simpleService; @TransactionAttribute(TransactionAttributeType.REQUIRED) public void process(){ final long start = System.currentTimeMillis(); for(int i=0; i<MAX; i++){ simpleService.getMap(); } final long end = System.currentTimeMillis(); log.info(MessageFormat.format("Process took {0} ms", end - start)); } } 

Then I have a simple CDI bean to call the process method.

Result:

When I call the process method several times in a row, the process time increases:

 Process took 900 ms Process took 1,100 ms Process took 1,200 ms Process took 1,400 ms 

And it continues to grow every time the method is called.

How can this be explained?

I am using Java JDK 1.7.0_25 and JBOSS EAP 6.1.

EDIT

By the way, the only way to "reset" is the processing time for this method - to restart the server.

+8
java java-ee jboss ejb
source share
2 answers

I tested with WildFly 8.1.0.Final and I get the following:

 Process took 900 ms Process took 600 ms Process took 400 ms Process took 300 ms Process took 130ms Process took 100ms 

And then it stabilizes for about 90 ms.

So, I think we can safely assume that the original problem was a bug in JBoss AS 7, which was fixed in WildFly 8.1. More than corrected, they even introduced some optimization!

CHANGE!

I apologize for everyone, I did the wrong diagnosis. This error has nothing to do with the JBoss version, but was caused by JRebel.

When I downloaded Wildfly, I did not run it in debug mode with the JRebel agent attached (which I constantly did with EAP 6.1). If I run JBoss EAP 6.1 without JRebel, the problem does not occur.

I'm so used to JRebel that I forgot that I turned it on!

I will raise a question with the JRebel team.

EDIT 2

The JRebel team investigated and was able to reproduce the defect. It was fixed in the nightly build and will be fixed in the next release (in August / September 2014).

+4
source share

Could you try the same test, but create a SimpleService interface, and the current SimpleService will look like SimpleServiceImpl, which will implement SimpleService.
I would suggest that cdi does some magic to wrap EJB. Hmm .. or another thing might try using @EJB injection instead of @Inject

0
source share

All Articles