From 8f8e0c71383d2b4b81989bcbf5db1c3781dffa52 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Sat, 10 Jan 2015 01:12:37 +0100 Subject: [PATCH] Use Async.go() in ReconnectionManager --- .../smack/ReconnectionManager.java | 7 +++---- .../org/jivesoftware/smack/util/Async.java | 20 +++++++++++++++++-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/ReconnectionManager.java b/smack-core/src/main/java/org/jivesoftware/smack/ReconnectionManager.java index 2c7c7e982..b52c8873a 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/ReconnectionManager.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/ReconnectionManager.java @@ -18,6 +18,7 @@ package org.jivesoftware.smack; import org.jivesoftware.smack.XMPPException.StreamErrorException; import org.jivesoftware.smack.packet.StreamError; +import org.jivesoftware.smack.util.Async; import java.lang.ref.WeakReference; import java.util.Map; @@ -250,10 +251,8 @@ public class ReconnectionManager { if (reconnectionThread != null && reconnectionThread.isAlive()) return; - reconnectionThread = new Thread(reconnectionRunnable); - reconnectionThread.setName("Smack Reconnection Manager (" + connection.getConnectionCounter() + ')'); - reconnectionThread.setDaemon(true); - reconnectionThread.start(); + reconnectionThread = Async.go(reconnectionRunnable, + "Smack Reconnection Manager (" + connection.getConnectionCounter() + ')'); } private final ConnectionListener connectionListener = new AbstractConnectionListener() { diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/Async.java b/smack-core/src/main/java/org/jivesoftware/smack/util/Async.java index b6af0204f..d22e06858 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/util/Async.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/util/Async.java @@ -18,15 +18,31 @@ package org.jivesoftware.smack.util; public class Async { - public static void go(Runnable runnable) { + /** + * Creates a new thread with the given Runnable, marks it daemon, starts it and returns the started thread. + * + * @param runnable + * @return the started thread. + */ + public static Thread go(Runnable runnable) { Thread thread = daemonThreadFrom(runnable); thread.start(); + return thread; } - public static void go(Runnable runnable, String threadName) { + /** + * Creates a new thread with the given Runnable, marks it daemon, sets the name, starts it and returns the started + * thread. + * + * @param runnable + * @param threadName the thread name. + * @return the started thread. + */ + public static Thread go(Runnable runnable, String threadName) { Thread thread = daemonThreadFrom(runnable); thread.setName(threadName); thread.start(); + return thread; } public static Thread daemonThreadFrom(Runnable runnable) {