0

is there a function or something in java/spring like in JS callback. where once first synchronous call is complete then start 2nd one and go over the same method. like suppose pick xml from one folder are complete and then goto same function but use different folder this time.

import org.json.*;
public class ConvertXMLToJSONArrayTest {
   public static String xmlString= "<?xml version=\"1.0\" ?><root><test       attrib=\"jsontext1\">tutorialspoint</test><test attrib=\"jsontext2\">tutorix</test></root>";
   public static void main(String[] args) {
      try {
         JSONObject json = XML.toJSONObject(xmlString); // converts xml to json
         String jsonPrettyPrintString = json.toString(4); // json pretty print
         System.out.println(jsonPrettyPrintString);
      } catch(JSONException je) {
         System.out.println(je.toString());
      }
   }
}
Lucky
  • 1
  • 1
  • 1
    Java is generally synchronous unless you want it to be. So when I say synchronous your tasks run one after other... On the other hand asynchronous are tasks running in parallel and once they complete their function callback is added to function stack trace which then executes. I suppose you don't need asynchronous methods to achieve what you mentioned – pavan kumar Jun 22 '20 at 20:05
  • Hey! You could be searching for [`CompletableFuture`](https://www.baeldung.com/java-completablefuture). You can chain async calls. – akuzminykh Jun 22 '20 at 20:07
  • Does this answer your question? [What is a callback method in Java? (Term seems to be used loosely)](https://stackoverflow.com/questions/19405421/what-is-a-callback-method-in-java-term-seems-to-be-used-loosely) – pavan kumar Jun 22 '20 at 20:11
  • Pavan you are right. I need synchronous call. currently I have a asynchronous and implements call() from callable. the issue is when call is made the creds to access both paths are different. earlier this method worked it was same creds. now we changed It. – Lucky Jun 22 '20 at 20:40

0 Answers0