Answer the question
In order to leave comments, you need to log in
Java access to main thread?
Framework : Vaadin flow
Comrades help.
The task is to periodically start receiving data in the stream and send a message to the main class (Eventbus).
Here is my code, it crashes on sending a message:
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
System.out.println("timer: "+Thread.currentThread());
Callable task = () -> {
//Выполняем какую-то фигню возвращающую результат
Login login = new Login();
login.setMESSAGE(MessageCode.LOGIN_ERROR);
return login;
};
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<Login> future = executor.submit(task);
try {
Login message = future.get();
MainView.eventBus.post(message);//Кидаем сообщение
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
executor.shutdown();
}
}, 0, 3500);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question