2015-11-02 175 views
0

當我點擊右鍵 - >停止時,螢火蟲9不會在eclipse中關閉,但是當我點擊停止在控制檯時,螢火蟲9會關閉。無法優雅地關閉wildfly

當試圖優雅的關閉,在控制檯輸出:

18:36:08,342 INFO [org.jboss.as.server] (management-handler-thread - 5) WFLYSRV0211: Suspending server 
18:36:08,345 INFO [org.jboss.as.server] (Thread-2) WFLYSRV0220: Server shutdown has been requested. 
18:36:08,428 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 81) WFLYUT0022: Unregistered web context: /csbasement 
18:36:08,441 INFO [org.ocpsoft.rewrite.servlet.RewriteFilter] (ServerService Thread Pool -- 81) RewriteFilter shutting down... 
18:36:08,442 INFO [org.ocpsoft.rewrite.servlet.RewriteFilter] (ServerService Thread Pool -- 81) RewriteFilter deactivated. 
18:36:08,460 INFO [org.wildfly.extension.undertow] (MSC service thread 1-1) WFLYUT0019: Host default-host stopping 

服務器的狀態停留在後停止,沒有停止過。 5分鐘左右後,日食對話未能停止服務器,這在控制檯:

19:29:11,600 WARN [com.arjuna.ats.arjuna] (Transaction Reaper) ARJUNA012117: TransactionReaper::check timeout for TX 0:ffffc0a80104:6ad8fb66:5637aa44:c in state RUN 
19:29:11,601 WARN [com.arjuna.ats.arjuna] (Transaction Reaper Worker 0) ARJUNA012095: Abort of action id 0:ffffc0a80104:6ad8fb66:5637aa44:c invoked while multiple threads active within it. 
19:29:11,601 WARN [com.arjuna.ats.arjuna] (Transaction Reaper Worker 0) ARJUNA012108: CheckedAction::check - atomic action 0:ffffc0a80104:6ad8fb66:5637aa44:c aborting with 1 threads active! 
19:29:11,602 WARN [com.arjuna.ats.arjuna] (Transaction Reaper Worker 0) ARJUNA012121: TransactionReaper::doCancellations worker Thread[Transaction Reaper Worker 0,5,main] successfully canceled TX 0:ffffc0a80104:6ad8fb66:5637aa44:c 

後,即使我得到404試圖訪問該Web應用程序的頁面時的狀態開始。我不確定錯誤中的含義:Unregistered web context: /csbasement。 csbasement是webapp的名稱。另外,當使用乾淨的webapp狀態保持啓動,所以我必須停止服務器,清理並重新啓動它。

當開始我有這個錯誤,但能正常開機:

19:17:16,344 ERROR [org.jboss.remoting.remote.connection] (XNIO-1 I/O-2) JBREM000200: Remote connection failed: java.io.IOException: An established connection was aborted by the software in your host machine 

編輯:

@Eager 
@Named 
@ApplicationScoped 
public class LaunchBackgroundTasks { 

    @EJB 
    private TwitterLatestTweetInterface twitterService; 
    private LinkedBlockingQueue<Tweet> msgList; 

    @PostConstruct 
    public void init() { 
     twitterService.makeLatestsTweets(); 
    } 
} 

@Stateless 
public class TwitterLatestTweets { 
    private LinkedBlockingQueue<Tweet> tweets; 
    @Inject 
    private LaunchBackgroundTasks caller; 


    @Asynchronous 
    public void makeLatestsTweets() { 
      ... 
     while (!hosebirdClient.isDone()) { 
      try { 
       String msg = msgQueue.take(); 
       Tweet tweet = format(msg); 
       tweets.put(tweet); 
       caller.setMsgList(tweets); 

      } catch (InterruptedException e) { 
       hosebirdClient.stop(); 
       e.printStackTrace(); 
      } 
     } 
    } 

而且我得到了鳴叫一個JSF頁面上像這樣:value="#{launchBackgroundTasks.msgList}",這是「在玻璃魚上工作」。

這並不異步啓動(java @Asynchronous Methods: not running async

@Eager 
@Named 
@ApplicationScoped 
public class TwitterLatestTweets { 

    private LinkedBlockingQueue<Tweet> tweets; 

    @PostConstruct 
    public void init() { 
     makeLatestsTweets(); 
    } 

    //notation not taken into account 
    @Asynchronous 
    public void makeLatestsTweets() { 


     // hosebirdClient is twitter streaming so I'm getting tweets as long as the app is alive. 
     while (!hosebirdClient.isDone()) { 
      try { 
       String msg = msgQueue.take(); 
       Tweet tweet = format(msg); 
       tweets.put(tweet); 
       } 
      } catch (InterruptedException e) { 
       hosebirdClient.stop(); 
       e.printStackTrace(); 
      } 
     } 
    } 
+0

@BalusC因爲我無法找到中斷的'@ Asynchronous'方法,我用代替普通線程的線程的方式。我的答案是否可行? – Ced

回答

0

我是個很固執使用@Asynchronous,因爲我希望我的線程管理,但我只是不能讓它那樣工作。我無法找到中斷異步方法的線程的方式。所以我回到了一個正常的線程來完成我想要的工作。

@Eager 
@Named 
@ApplicationScoped 
public class LaunchBackgroundTasks { 

    @EJB 
    TopStreamInterface topStream; 
    Thread twitterThread; 

List<Tweet> tweets; 

    @PostConstruct 
    public void init() { 
     tweets = new LinkedList<Tweet>(); 
     twitterThread = new Thread(new TwitterLatestTweets(this)); 
     twitterThread.start(); 

    } 

    @PreDestroy 
    public void destroyTwitterClient() { 
     twitterThread.interrupt(); 
    } 
} 

和螺紋:

public class TwitterLatestTweets implements Runnable { 

    private final static String BUNDLE_BASENAME = "configuration.twitter"; 
    private final static String CONSUMER_KEY = ResourceBundle.getBundle(
      BUNDLE_BASENAME).getString("consumerKey"); 
    private final static String CONSUMER_SECRET = ResourceBundle.getBundle(
      BUNDLE_BASENAME).getString("consumerSecret"); 
    private final static String TOKEN = ResourceBundle.getBundle(
      BUNDLE_BASENAME).getString("token"); 
    private final static String SECRET = ResourceBundle.getBundle(
      BUNDLE_BASENAME).getString("secret"); 
    // private LinkedBlockingQueue<Tweet> msgList; 
    private List<Long> userIds; 
    private int tweetListSize = 10; 

    TwitterLatestTweets(LaunchBackgroundTasks caller) { 
    this.caller = caller; 
    } 
     @Override 
    public void run() { 
     makeLatestsTweets(); 
    } 

    public void makeLatestsTweets() { 

     BlockingQueue<String> msgQueue = new LinkedBlockingQueue<String>(100); 
     StatusesFilterEndpoint hosebirdEndpoint = new StatusesFilterEndpoint(); 

     userIds = addFollowings(); 

     hosebirdEndpoint.followings(userIds); 

     Authentication hosebirdAuth = new OAuth1(CONSUMER_KEY, CONSUMER_SECRET, 
       TOKEN, SECRET); 

     Client client = new ClientBuilder().name("test") 
       .hosts(Constants.STREAM_HOST).endpoint(hosebirdEndpoint) 
       .authentication(hosebirdAuth) 
       .processor(new StringDelimitedProcessor(msgQueue)).build(); 

     client.connect(); 

     while (!client.isDone()) { 
      try { 
       String msg = msgQueue.take(); 
       //... 
       caller.setTweets(aTweetLinkedList); 
       } 
      } catch (InterruptedException e) { 
       System.out.println("twitter interrupted"); 
       client.stop(); 
       e.printStackTrace(); 
      } 
     } 
    } 
}