I have a method which will execute a long running portion of code. I want to report back to the code that invoke my method the progress I am making in executing the code, for example to let the invoker know I am in pre-processing section, or processing, or validation....
Maybe not exactly to the called routine, but you can report progress to, say, the instance that invoked the called method, or to some other part of your code. I think this is probably what you meant anyway, since the next execution point of the calling method is sitting in the call stack, waiting for a return.
Pass a reference to a "listener" class to the call; as a simple example, perhaps you have a class called ProgressListener, implementing the method reportProgress(String progressString). The listener could be the same class as has the long-running call, and you could pass this as the instance you want to receive the progress reports.
Then have the called routine call reportProgress() with whatever string it wants the caller to know about.
This will work if all you are going to do is, say, display the string in the console while your code grinds away. Things can get much more elaborate if you want to estimate percentage of task done, or whatever. A String is a fairly crude way of reporting progress, is all I'm saying. And of course if THAT were all you wanted to do, the long-running method could do it itself.
But the fact that the caller and callee are in the same thread needn't keep you from using a listener.
Now, if you DO have a GUI, say in Swing, there may be restrictions about what you can or should do in a long-running calculation thread. Those considerations depend on whether you have a UI and which one you have, so I/we can't specify them here.
Thanks for the reply. I am looking to know how to implement a listener to get updates on the method progress. That particular class you mentioned is in Java EE while I am using swing.
Basically, I want to update the invoker which is client code (Client to my method, not a client server architecture) about the progress of the method. The invoker can either update a GUI, print the text to the console or whatever it wants to do.