Clear memory during infinite loop

0
For a project we are using Amazon SQS. In a Microflow we are continuously polling SQS for new messages (Amazon describes the mechanism as long polling) in an infinite loop. Each incoming message is processed using a Queue. We notice that objects accumulate in memory over the course of time, even if non-persistent objects are explicitely deleted. Is there a solution to fix this inside the Microflow? I could also implement a fixed thread pool that is running each iteration of the Microflow in a separate context, which ensures that all objects in the context are released.
asked
4 answers
1

I think the problem is that the microflow is running in the same context and the same transaction all the time. You could remove the loop and use a recursive microflow call but it would still be the same context and transaction.

 

I created a module called “Follow Up Microflow” that can execute a microflow when the calling microflow is terminated. It will run in a seperate context and in a seperate transaction. Maybe it helps. Maybe you can just extract some ideas from it and build something on your own. It’s pretty new and is something like a side project. I don’t have a lot of feedback yet but it sounds like it could solve your problem.

answered
1

Why not use a scheduled event for this? Have it run every 1 minute or so?

It will automatically solve your issue because each invokation will have its own context

answered
1

This works quite well. In the RunnableImplementation you can configure an infinite loop that executes a Microflow. Before execution you can create a system context. After execution you can destroy the session.

ExecutorService executorService = Executors.newFixedThreadPool(numberOfThreads);

for (int i = 0; i < numberOfThreads; i++) {
	Runnable runnable = new RunnableImplementation(logger, microflowToExecute);
	executorService.submit(runnable);
}

 

answered
0

Hi guys, thanks for your answers! @Andrej, I will not use scheduled events as I want to retrieve as many jobs as possible during peak loads.

answered