Search code examples
javareturnhessian

Return a string values without using return statment in Java


Thank in advance.

I am looking for message type or anything which is fast and easy way to return a String value in Java.

for example. I have a method

void getStringvalues(int a, int b){

int c = a + b;

...
...
....


}

And the above Method is called from Hessian php server.

So i have to send a message back to php from Java like an acknowledgement. which has to be a string. Is there any way to do that.

I can use Return, but java method is dealign with huge db and caluculations. And php's session will expire until i finish the whole process and send return type " ". at the end.

Or can i use return type in the beginning of the process ?

Thank again,


Solution

  • If I understand correctly, you want your Java method to return an intermediate result, and then continue. So you have two solutions:

    1. Split the method in two parts, and call each submethod from the client:

      intermediateResult = server.doFirstPart();
      server.doSecondPart();
      
    2. Make the method do the second part in a separate thread:

      public String doEverything() {
          ...
          String intermediateResult = ...;
          Thread t = new Thread(...);
          t.start(); // launch the thread to compute the rest asynchronously
          return intermediateResult;
      }