Добрый день. Помогите добавить в мой код поток с остановкой sleep.
Вот пример который я хочу добавить
Вот мой код
package test;
import java.io.BufferedReader;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Scanner;
import org.json.JSONObject;
public class MAin {
public static void main(String[] args) {
String urlVK = "https://api.vk.com/method/photos.search?&radius=10000&lat=48.24523&long=58.2523&access_token=7075966f7075966f7075966f577018909e770757075966f2dfd2579655817dfd28d3bfd&v=5.103";
try {
URL url = new URL(urlVK);
// read from the URL
Scanner scan = new Scanner(url.openStream());
String str = new String();
while (scan.hasNext())
str += scan.nextLine();
scan.close();
// build a JSON object
JSONObject obj = new JSONObject(str);
int pageName = obj.getJSONObject("response").getInt("count");
System.out.print(pageName);
try {
for(int i=0;i < pageName; i=i+1000) {
String urlVKoffset = "https://api.vk.com/method/photos.search?&radius=10000&lat=48.24523&long=58.2523&access_token=7075966f7075966f7075966f577018909e770757075966f2dfd2579655817dfd28d3bfd&v=5.103"
+ "&offset=" + i;
URL objVK = new URL(urlVKoffset);
HttpURLConnection connection = (HttpURLConnection) objVK.openConnection();
connection.setRequestMethod("GET");
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
/*
System.out.println(response.toString());
*/
try (FileWriter file = new FileWriter("response-vk" + i + ".json")) {
file.write(response.toString());
}
}
}catch(Exception e){}
}
catch(Exception e){}
}
}