<?xml version="1.0" encoding="UTF-8"?>
<test-data xmlns="http://pmd.sourceforge.net/rule-tests"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://pmd.sourceforge.net/rule-tests https://pmd.sourceforge.io/rule-tests_1_0_0.xsd">
    <test-code>
        <description>AvoidManuallyCreateThreadRule</description>
        <expected-problems>3</expected-problems>
        <expected-linenumbers>16,19,23</expected-linenumbers>
        <code><![CDATA[

package com.alibaba.idea.pmd.test.concurrent;

import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author caikang
 * @date 2016/11/15
 */
public class ThreadCreateTest {
    static {
        new Thread();
    }
    private Thread thread = new Thread();

    private Thread createThread(){
        return new Thread();
    }

    public void testParamter(){
    Thread thread = new Thread();

    }

}


        ]]></code>
    </test-code>
    <test-code>
        <description>right</description>
        <expected-problems>0</expected-problems>
        <code><![CDATA[

package com.alibaba.idea.pmd.test.concurrent;

import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author caikang
 * @date 2016/11/15
 */
public class ThreadCreateTest {
     {
        Runtime.getRuntime().addShutdownHook(
new Thread()
);
    }
    private ThreadFactory threadFactory = r -> {
        Thread thread1 = new Thread(r);
        thread1.setName("kdsljf");
        return thread1;
    };

    private ThreadFactory threadFactory1 = new ThreadFactory() {
        @Override
        public Thread newThread(Runnable r) {
            Thread thread = new Thread();
            thread.setName("xxx");
            return thread;
        }
    };

    private ThreadFactory threadFactory2 = new ThreadFactory() {
        @Override
        public Thread newThread(Runnable r) {
            return new ThreadFactory() {
                @Override
                public Thread newThread(Runnable r) {
                    Thread thread = new Thread();
                    return thread;
                }
            }.newThread(r);
        }
    };

    public void testNewThread(){
        new ThreadFactory(){

            @Override
            public Thread newThread(Runnable r) {
                return new Thread();
            }
        }.newThread(new Runnable() {
            @Override
            public void run() {

            }
        });
    }

    public void testParamter(){
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(10, 10, 100, TimeUnit.MILLISECONDS, new SynchronousQueue<Runnable>(),
                r -> {
                    Thread thread1 = new Thread(r);
                    thread1.setName("xxx");
                    return thread1;
                });
        new ThreadPoolExecutor(10, 10, 100, TimeUnit.MILLISECONDS, new SynchronousQueue<Runnable>(),
                r -> {
                    Thread thread1 = new Thread(r);
                    thread1.setName("xxx");
                    return thread1;
                });
        new ThreadPoolExecutor(10, 10, 100, TimeUnit.MILLISECONDS, new SynchronousQueue<Runnable>(),
                new ThreadFactory() {
                    @Override
                    public Thread newThread(Runnable r) {
                        return new Thread();
                    }
                });
    }

    class MyThreadFactory implements ThreadFactory {
        /**
         * Constructs a new {@code Thread}.  Implementations may also initialize
         * priority, name, daemon status, {@code ThreadGroup}, etc.
         *
         * @param r a runnable to be executed by new thread instance
         * @return constructed thread, or {@code null} if the request to create a thread is rejected
         */
        @Override
        public Thread newThread(Runnable r) {
            return new Thread();
        }
    }
}


        ]]></code>
    </test-code>
</test-data>
