@Startup - Wildfly Server start method if application successful deployed

wildfly startup

625 просмотра

2 ответа

How can I start a method even the server is fully up and running? Currently I´m implement a file watcher. I want to start the File watcher at start from the server. But due to the while() loop in my method the server will not start and go in the timeout. Therefore I want to start the FileWatcher as soon the server and my web app deployed successful.

@Startup
@Singleton
public class FileWatcher {
    @PostConstruct
    public void init() {
        System.out.println("Init file Watcher ");
        try {
            doStartFileWatcher();
        } catch (Exception e) {
        }
    }
}

How can I solve this?

Автор: Marc Meister Источник Размещён: 08.11.2019 11:20

Ответы (2)


0 плюса

At a guess, you are running something periodically for the FileWatcher class. How about a change:

@Startup
@Singleton
public class FileWatcher {

    @Schedule(hour = "*", minute = "*",persistent = false)
    private void runFileWatcher() {
    }
}

The runFileWatcher method will now run every minute at the 0 second (i.e. 10:08:00AM). Would this work better?

Автор: stdunbar Размещён: 20.08.2016 04:09

0 плюса

Maybe you should use the JDK WatchService API: https://docs.oracle.com/javase/tutorial/essential/io/notification.html

Автор: ehsavoie Размещён: 22.08.2016 07:15
Вопросы из категории :
32x32