1

I want to, in a running java application, get the exact point of execution or line of running code.

I'm researching some fault tolerance approaches and trying to implements some solutions. I'm serializing an Thread object to file and forcing an shutdown on my application. My objective is to re-run the serializable Thread not from start of "run" method, but from the line when it was serialized.

The problem is: in a running Thread, after call an "pause" method, get the line of a paused code. After this, I want to instantiate a new Thread of it type and running from that line.

Anyone knows how can I do it?

  • You can't just start (or stop) execution at an arbitrary point in your code. – Andy Turner Mar 02 '16 at 15:40
  • But if a Thread is executing and pause, when it returns the execution, it will start where stopped. Can I get the this information? – Pergentino Araújo Mar 02 '16 at 15:45
  • 1
    Sounds like a possible [XY problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). What is the higher-level problem that you are trying to solve? – Solomon Slow Mar 02 '16 at 16:03
  • How do you intend to "pause" a thread by invoking pause() method? Wouldn't you invoke an interrupt, or let the running thread check for the pause flag, periodically? In that case, the thread has stopped at the point when it checked for the pause flag. What are we missing here? – Manish Maheshwari Mar 02 '16 at 21:20

1 Answers1

1

What you need is a serializable continuation. However, of the solutions I have heard of they are either;

  • not a complete solution
  • very slow to maintain enough information that you could stop it at any point.

A better approach is to have a state machine where you can record all the inputs and thus you can recreate the application at any point by replaying these events.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130