1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-09-10 18:59:41 +02:00

Move SmackExecutorThreadFactory out of

AbstractXMPPConnection. And use it in PingManager.
This commit is contained in:
Florian Schmaus 2014-12-19 12:53:16 +01:00
parent eb48d02673
commit 18ac83cf8c
3 changed files with 45 additions and 42 deletions

View file

@ -34,7 +34,6 @@ import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
@ -73,6 +72,7 @@ import org.jivesoftware.smack.provider.ProviderManager;
import org.jivesoftware.smack.rosterstore.RosterStore;
import org.jivesoftware.smack.util.DNSUtil;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smack.util.SmackExecutorThreadFactory;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smack.util.dns.HostAddress;
import org.jxmpp.util.XmppStringUtils;
@ -238,29 +238,6 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
// @formatter:on
);
/**
* SmackExecutorThreadFactory is a *static* inner class of XMPPConnection. Note that we must not
* use anonymous classes in order to prevent threads from leaking.
*/
private static final class SmackExecutorThreadFactory implements ThreadFactory {
private final int connectionCounterValue;
private final String name;
private int count = 0;
private SmackExecutorThreadFactory(int connectionCounterValue, String name) {
this.connectionCounterValue = connectionCounterValue;
this.name = name;
}
@Override
public Thread newThread(Runnable runnable) {
Thread thread = new Thread(runnable);
thread.setName("Smack Executor - " + name + ' ' + count++ + " (" + connectionCounterValue + ")");
thread.setDaemon(true);
return thread;
}
}
private Roster roster;
/**

View file

@ -0,0 +1,42 @@
/**
*
* Copyright 2014 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smack.util;
import java.util.concurrent.ThreadFactory;
/**
* SmackExecutorThreadFactory creates daemon threads with a particular name. Note that you should
* not use anonymous inner classes for thread factories in order to prevent threads from leaking.
*/
public final class SmackExecutorThreadFactory implements ThreadFactory {
private final int connectionCounterValue;
private final String name;
private int count = 0;
public SmackExecutorThreadFactory(int connectionCounterValue, String name) {
this.connectionCounterValue = connectionCounterValue;
this.name = name;
}
@Override
public Thread newThread(Runnable runnable) {
Thread thread = new Thread(runnable);
thread.setName("Smack Executor - " + name + ' ' + count++ + " (" + connectionCounterValue + ")");
thread.setDaemon(true);
return thread;
}
}