Fix synchronization
This commit is contained in:
parent
d24eecca2b
commit
0a896dce38
@ -60,13 +60,12 @@ public class DefaultBotSession implements BotSession {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void start() {
|
||||
if (running.get()) {
|
||||
public void start() {
|
||||
if (running.compareAndSet(false, true)) {
|
||||
throw new IllegalStateException("Session already running");
|
||||
}
|
||||
|
||||
running.set(true);
|
||||
|
||||
synchronized (this) {
|
||||
lastReceivedUpdate = 0;
|
||||
|
||||
readerThread = new ReaderThread(updatesSupplier, this);
|
||||
@ -77,14 +76,14 @@ public class DefaultBotSession implements BotSession {
|
||||
handlerThread.setName(callback.getBotUsername() + " Telegram Executor");
|
||||
handlerThread.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void stop() {
|
||||
if (!running.get()) {
|
||||
throw new IllegalStateException("Session already stopped");
|
||||
}
|
||||
|
||||
running.set(false);
|
||||
@Override
|
||||
public void stop() {
|
||||
if (!running.compareAndSet(true, false)) {
|
||||
throw new IllegalStateException("Session already stopped");
|
||||
}
|
||||
synchronized (this) {
|
||||
|
||||
if (readerThread != null) {
|
||||
readerThread.interrupt();
|
||||
@ -98,6 +97,7 @@ public class DefaultBotSession implements BotSession {
|
||||
callback.onClosing();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setUpdatesSupplier(UpdatesSupplier updatesSupplier) {
|
||||
this.updatesSupplier = updatesSupplier;
|
||||
|
Loading…
Reference in New Issue
Block a user