oops! забыли про асинхронный поток
This commit is contained in:
@@ -30,6 +30,7 @@ public class VkApi implements Runnable {
|
||||
|
||||
private Timer timer = new Timer();
|
||||
private int countCallApiPerSecond = 0;
|
||||
private Thread asyncExecApiThread = null;
|
||||
|
||||
private BlockingQueue<TaskMethod> queueExecute = new SynchronousQueue<>();
|
||||
|
||||
@@ -66,6 +67,11 @@ public class VkApi implements Runnable {
|
||||
}
|
||||
|
||||
public void execApiAsync(String apiMethod, Map<String, String> params, Callback callback) {
|
||||
if (asyncExecApiThread == null) {
|
||||
asyncExecApiThread = new Thread(this);
|
||||
asyncExecApiThread.start();
|
||||
}
|
||||
|
||||
queueExecute.offer(TaskMethod.builder()
|
||||
.method(apiMethod)
|
||||
.postData(params)
|
||||
@@ -123,6 +129,12 @@ public class VkApi implements Runnable {
|
||||
return gson.fromJson(response.getContent(), JsonObject.class);
|
||||
}
|
||||
|
||||
public void shutdownAsyncThread() {
|
||||
if (asyncExecApiThread != null && !asyncExecApiThread.isInterrupted()) {
|
||||
asyncExecApiThread.interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
private String paramsToString(Map<String, String> params) {
|
||||
final StringJoiner sj = new StringJoiner("&");
|
||||
sj.add("access_token=" + accessToken).add("v=" + apiVersion);
|
||||
|
||||
Reference in New Issue
Block a user