Когда я вызываю sendDM () во второй раз, я получаю предупреждение о взаимоблокировке. Как я могу это исправить?
Я использую JDA Api, и я пытаюсь получить сообщение, которое я отправил с RestAction .complete ()
private void start(){
sendDM(getP1().getUser());
sendDM(getP2().getUser());
EmbedBuilder embedBuilder = new EmbedBuilder();
textChannel.sendMessage(p1.getUser().getAsMention() + " " + p2.getUser().getAsMention()).queue();
textChannel.sendMessage(embedBuilder.setTitle("**Match has started - #" + getGameId() + "**")
.addField("Info", "ID: " + getGameId() + "\nMap: 7189-0031-5500" + "\nStatus: " + getStatus().toString(),true)
.addField("Player 1", p1.getUser().getAsMention() + " - Host", false)
.addField("Player 2", p2.getUser().getAsMention(), false)
.addField("Lobby", textChannel.getAsMention(), false)
.setFooter("Both participants will receive a Private Message where they can submit match results", null).build())
.queue();
}
private void sendDM(User user){
EmbedBuilder embedBuilder = new EmbedBuilder();
user.openPrivateChannel().queue((channel) ->
{
channel.sendMessage(p1.getUser().getAsMention() + " " + p2.getUser().getAsMention()).queue();
Message message = channel.sendMessage(embedBuilder.setTitle("**Match has started - #" + getGameId() + "**")
.addField("Info", "ID: " + getGameId() + "\nMap: 7189-0031-5500" + "\nStatus: " + getStatus().toString(),true)
.addField("Player 1", p1.getUser().getAsMention() + " - Host", false)
.addField("Player 2", p2.getUser().getAsMention(), false)
.addField("Lobby", textChannel.getAsMention(), false)
.addField("**If you win**", ":white_check_mark:", true)
.addField("**If you loose**", ":x:", true)
.setFooter("Both participants will receive a Private Message where they can submit match results", null).build())
.complete();
message.addReaction("\u274C").complete();
message.addReaction("\u2705").complete();
});
}
Я ожидаю, что он просто вернетСообщение, но я получаю эту ошибку:
[ForkJoinPool.commonPool-worker-1] ERROR net.dv8tion.jda.api.requests.RestAction - Encountered error while processing success consumer
java.lang.IllegalStateException: Preventing use of complete() in callback threads! This operation can be a deadlock cause
at net.dv8tion.jda.internal.requests.RestActionImpl.complete(RestActionImpl.java:187)
at net.dv8tion.jda.api.requests.RestAction.complete(RestAction.java:357)
at match.Match.lambda$sendDM$0(Match.java:71)
at net.dv8tion.jda.api.requests.Request.lambda$onSuccess$0(Request.java:83)
at java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1402)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)