API request of blockchain.info over Java stops spontaneously

In my java class, I extract the hash of transactions from the files of blk…dat, then obtain the data of the corresponding transactions via reading from the URL: https://blockchain.info/rawtx/+ hash. At one time, my program stopped after calling the urls for 1370 times, at the other time, my program stopped after calling the urls for 2243 times. The program is not terminated and will not proceed no matter how long I wait.

What is going on in this case?

Since the number of call exceeds the the hard limits described here: https://blockchain.info/api, I suspect that it is not a problem of I lacking an API-Key. But in the case it is the reason, how could I get an API-Key? I don’t have a website (the java-application is for my bachelor thesis), and it seems that quite a few people online have issue with obtaining the API-Key from blockchain.info.

Could it because of something about the network quality I am using, if yes, is there any way to work around it with my java program?

If it is a inherent problem from the side of blockchain.info, could someone recommend me an alternative way to attain similar data of transactions?

My code:

import org.bitcoinj.core.*; import org.bitcoinj.core.Transaction; import org.bitcoinj.utils.*; import java.io.*; import java.net.URL; import java.nio.charset.Charset; import java.util.*; import org.bitcoinj.params.MainNetParams;   import org.json.*;  public class ParseFromDat {     private static String readAll(Reader rd) throws IOException {         StringBuilder sb = new StringBuilder();         int cp;         while ((cp = rd.read()) != -1) {             sb.append((char) cp);         }         return sb.toString();     }      public static JSONObject readJsonFromUrl(String url) throws IOException, JSONException {         InputStream is = new URL(url).openStream();         try {             BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));             String jsonText = readAll(rd);             JSONObject json = new JSONObject(jsonText);             return json;         } finally {             is.close();         }     }      public static void main(String[] args) throws IOException, JSONException {         Context.getOrCreate(MainNetParams.get());          // Arm the blockchain file loader.         NetworkParameters np = new MainNetParams();         List<File> blockChainFiles = new ArrayList<File>();         blockChainFiles.add(new File("C:\Users\...\AppData\Roaming\Bitcoin\blocks\blk00514.dat"));         BlockFileLoader bfl = new BlockFileLoader(np, blockChainFiles);          // define files to be written into         PrintWriter transactions = new PrintWriter(new File("./csvs/transactions.csv"));         StringBuilder traStr = new StringBuilder();         traStr.append("tranHashString:ID(Trans)\n");         PrintWriter sendAdd = new PrintWriter(new File("./csvs/sendAdd.csv"));         StringBuilder sendStr = new StringBuilder();         sendStr.append("addr:ID(SendAdd),value,tranHashString,addr_tag_link,addr_tag\n");         PrintWriter receiveAdd = new PrintWriter(new File("./csvs/receiveAdd.csv"));         StringBuilder receiStr = new StringBuilder();         receiStr.append("addr:ID(ReceAdd),value,tranHashString,addr_tag_link,addr_tag\n");          PrintWriter inTran = new PrintWriter(new File("./csvs/intran.csv"));         StringBuilder inStr = new StringBuilder();         inStr.append(":START_ID(SendAdd),:END_ID(Trans)\n");         PrintWriter outTran = new PrintWriter(new File("./csvs/outtran.csv"));         StringBuilder outStr = new StringBuilder();         outStr.append(":START_ID(Trans),:END_ID(ReceAdd)\n");          // Iterate over the blocks in the dataset.         int counter = 0;         for (Block block : bfl) {             System.out.println("aaaa");             List<Transaction> trans = block.getTransactions();             for (Transaction ta : trans) {                 System.out.println("bbbb");                 traStr.append(ta.getHashAsString());                 traStr.append("\n");                         System.out.println("bbbb1 " + (counter++));                 System.out.println(ta.getHashAsString());                 JSONObject json = readJsonFromUrl("https://blockchain.info/rawtx/" + ta.getHashAsString());                 JSONArray inputs = json.getJSONArray("inputs");                 for (int i = 0; i < inputs.length(); i++) {                     if (inputs.getJSONObject(i).has("prev_out")) { // it is possible that the value is null even when prev_out is not null                         System.out.println("ccc");                         JSONObject prevOut = (JSONObject) (inputs.getJSONObject(i).get("prev_out"));                         inStr.append(prevOut.get("addr").toString());                         inStr.append(',');                         inStr.append(ta.getHashAsString());                         inStr.append("\n");                          sendStr.append(prevOut.get("addr").toString());                         sendStr.append(',');                         sendStr.append(prevOut.get("value").toString());                         sendStr.append(',');                         sendStr.append(ta.getHashAsString());                          if (prevOut.has("addr_tag_link") || prevOut.has("addr_tag")) {                             if (prevOut.has("addr_tag_link") && prevOut.has("addr_tag")) {                                 sendStr.append(prevOut.get("addr_tag_link").toString());                                 sendStr.append(',');                                 sendStr.append(prevOut.get("addr_tag").toString());                             } else if (prevOut.has("addr_tag_link")) {                                 sendStr.append(prevOut.get("addr_tag_link").toString());                                 sendStr.append(',');                                 sendStr.append("null");                             } else {                                 sendStr.append("null");                                 sendStr.append(',');                                 sendStr.append(prevOut.get("addr_tag").toString());                             }                         }                         sendStr.append("\n");                     }else{                         continue;                     }                 }                 JSONArray out = json.getJSONArray("out");                 for (int i = 0; i < out.length(); i++) {                     JSONObject outItem = out.getJSONObject(i);                     if (outItem.has("addr")) { // it is possible that the add and value is null?                         outStr.append(ta.getHashAsString());                         outStr.append(',');                         outStr.append(outItem.get("addr").toString());                         outStr.append("\n");                          receiStr.append(outItem.get("addr").toString());                         receiStr.append(',');                         receiStr.append(outItem.get("value").toString());                         receiStr.append(',');                         receiStr.append(ta.getHashAsString());                          if (outItem.has("addr_tag_link") || outItem.has("addr_tag")) {                             if (outItem.has("addr_tag_link") && outItem.has("addr_tag")) {                                 receiStr.append(outItem.get("addr_tag_link").toString());                                 receiStr.append(',');                                 receiStr.append(outItem.get("addr_tag").toString());                             } else if (outItem.has("addr_tag_link")) {                                 receiStr.append(outItem.get("addr_tag_link").toString());                                 receiStr.append(',');                                 receiStr.append("null");                             } else {                                 receiStr.append("null");                                 receiStr.append(',');                                 receiStr.append(outItem.get("addr_tag").toString());                             }                         }                         receiStr.append("\n");                     }else{                         continue;                     }                  }              }          }         transactions.write(traStr.toString());         transactions.close();         sendAdd.write(sendStr.toString());         sendAdd.close();         receiveAdd.write(receiStr.toString());         receiveAdd.close();         inTran.write(inStr.toString());         inTran.close();         outTran.write(outStr.toString());         outTran.close();     } } 

Recent Questions – Bitcoin Stack Exchange