@SuppressWarnings("all")
    @Override
    public Thread newThread(final Runnable r) {
        Requires.requireNonNull(r, "runnable");

        final String name2 = this.name + this.id.getAndIncrement();
        final Runnable r2 = wrapRunnable(r);
        final Runnable r3 = new Runnable() {

            @Override
            public void run() {
                AffinityLock al = null;
                try {
                    al = acquireLockBasedOnLast();
                } catch (final Throwable ignored) {
                    // Defensive: ignored error on acquiring lock
                }
                try {
                    r2.run();
                } finally {
                    if (al != null) {
                        try {
                            al.release();
                        } catch (final Throwable ignored) {
                            // Defensive: ignored error on releasing lock
                        }
                    }
                }
            }
        };

        final Thread t = wrapThread(this.group, r3, name2);

        try {
            if (t.isDaemon() != this.daemon) {
                t.setDaemon(this.daemon);
            }

            if (t.getPriority() != this.priority) {
                t.setPriority(this.priority);
            }
        } catch (final Exception ignored) {
            // Doesn't matter even if failed to set.
        }

        LOG.info("Creates new {}.", t);

        return t;
    }
This is a ThreadFactory which assigns threads based the strategies provided.

If no strategies are provided AffinityStrategies.ANY is used.

@author jiachun.fjc
jraft-rheakv/rheakv-core/src/main/java/com/alipay/sofa/jraft/rhea/util/concurrent/AffinityNamedThreadFactory.java