There's a hidden feature in FreeMarker 2 that allows templates be interrupted with Thread.interrupt(). This can be used to limit the template execution time (one thread processes the template, the other waits for it to finish with a timeout, and then interrupts the template processing thread). To see this in action, go to http://freemarker-online.kenshoo.com/ and enter some very long loop. The processing will be aborted with timeout. The related part of the source code is around here: https://github.com/kenshoo/freemarker-online/blob/master/src/main/java/com/kenshoo/freemarker/services/FreeMarkerService.java#L123
That's the closes I can think of right now. But I'm open to ideas, because this used to be concern if you allow users to write templates. The problem with limiting #list iterations is that you can nest #list-s into each other, so it's easy to square, cube, etc. your iteration limit. (There are other fun ways of doing infinitely running templates too, like with recursion. That's why simply measuring how long the template is running is certainly the most robust solution.) If you have some collections that you know shouldn't be fully listed, then perhaps you should wrap those into your own TemplateSequenceModel implementation. Thursday, February 23, 2017, 3:14:06 PM, Christoph Rüger wrote: > We would like to hook into loops (<#list>) to e.g. count the number of > iterations and react based on some business conditions. For example stop > with an Exception after 10k iterations. > > I would think about some kind of callback which we can register which is > called by freemarker inside <#list> iterations, so that our callback code > can do whatever is needed. > > Is something like that possible already (haven't checked code yet) or > planned for FM3? > > Thanks > Christoph > -- Thanks, Daniel Dekany