2014-06-11 4 views
1

데이터베이스가 준비되었는지 확인하는 스레드가 있습니다. 데이터베이스가 사용 가능할 때 스레드가 종료됩니다. 그러나 어떤 경우에는 데이터베이스가 준비되기 전에 Wildfly 서버가 종료됩니다. 이 경우 스레드가 아직 살아 있기 때문에 Wildfly가 종료되지 않습니다.Wildfly/JBoss의 셧다운 훅/이벤트

이 스레드를 알리는 방법을 찾고 있습니다. 또는 해당 스레드를 중지하기 위해 Wildfly 서버의 상태 (실행, 종료, 시작 등)를 확인할 수있는 가능성을 찾고 있습니다.

아이디어가 있으십니까?

답변

2

Thread.setDaemon(true)을 설정해야합니다.

WildFly가 실행 중인지 확인하는 한 ModelControllerClient을 연결하고 서버 상태를 검사 할 수 있습니다. 연결되지 않으면 다운 될 가능성이 있습니다. 또는 적어도 관리 연결이 끊어졌습니다.

예 :

public static boolean isServerRunning() throws IOException { 
    try (final ModelControllerClient client = ModelControllerClient.Factory.create(InetAddress.getLocalHost(), 9990)) { 
     final ModelNode address = new ModelNode().setEmptyList(); 
     final ModelNode op = Operations.createReadAttributeOperation(address, "server-state"); 
     final ModelNode result = client.execute(op); 
     if (Operations.isSuccessfulOutcome(result)) { 
      final String state = Operations.readResult(result).asString(); 
      switch (state) { 
       case "running": 
       case "reload-required": 
       case "restart-required": 
        return true; 
      } 
     } 
     return false; 
    } 
} 
+0

가 거기 응용 프로그램에 직접 주입 할 수있는 @Resource? –