To infinity loops and beyond
Last week ended on a high note; our blog was mentioned by the Mendix Tech blog! It was great seeing a picture of our blog on theirs, and a thought occurred to me; what if I post a picture of their blog displaying a picture of our blog, would this cause an infinite loop? Well, theres only one way to find out! Before I do however, I just want to thank Mendix Tech Blog and co for their recognition, we appreciate it and we love reading the helpful and insightful articles and posts on your blog. Here goes..
..so if you are reading this, it means that all is well and that the internet survived my evil infinite loop experiment. But since we are on the topic of loops and evil experiments, have you ever looped your Mendix Modeler into infinity? Lets investigate some basic recurring looping scenarios.
Event handlers
In Mendix 101, you’ll learn that you should never commit the same entity on which the event handler was triggered, with the exception of “Commit without Events“. If you do, this will cause a cascade event to occur and will loop until your java memory runs out. Luckily, this happens really quickly and you are presented with a thick red line in your console output stating a Stack Overflow exception or “An unhandled error occurred in the MxRuntime.”
The consequences of you actions are fairly benign and you’ll realize the error of your ways soon, unless you only find this inside production. Hopefully you are exercising the best practice of testing your app properly before deploying it to production, right?
To infinity and beyond
So, lets see what a real infinite loop could look like, one which runs away. When this occurs, there isn’t a real obvious symptom or sign informing you of the situation, unless you have introduced a logging- or some other feedback artifact and and you happen to be monitoring your app. In most cases, you will probably start by suspecting it when your server feels like its dying a slow death.
If you do and want to follow your gut, open up the Windows Task Manager (Ctrl-Shift-Escape for short) and check if your CPU reports unusually high activity by a javaw.exe process.
Lets simulate a loop using a simple microflow. We’ll see that our javaw.exe process quickly ramps up in memory, but levels; mine stopped climbing at 304Mb, results may vary. However the constantly high CPU usage should be a dead giveaway that something is not right.
If you are running the modeler, you’ll find that its futile stopping the server, so if you are in the mood of gambling with which colour wire to cut, you’ll have to kill the active javaw.exe process which will cause your computer and modeler to return to a state of normality.
Thats some looping scenarios in a nutshell. We’ll be covering some looping patterns in the future, but unless you love reaching terminal velocity while playing portal or other such fun hobbies, try avoid infinite loops in your modeler.



