Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java - Save/restore call stack

Tags:

java

callstack

Is it possible to save the state of the call stack during execution and later restore the stack to that state, restarting at the top-most method call?

like image 900
user973758 Avatar asked Dec 09 '22 07:12

user973758


1 Answers

I strongly suggest to change your paradigm. Instead of manipulating the call stack (and very probably corrupting your JVM), think about incorporating the "call stack" somehow in your algorithm.

You may use the Strategy/Command/Undo design pattern and store the objects to your own logical stack, over which you have full control.

There is a related question Way to go from recursion to iteration with a lot of good answers.

like image 78
Honza Zidek Avatar answered Dec 10 '22 21:12

Honza Zidek