package shop.alien.util.thread;

import java.util.concurrent.ConcurrentLinkedQueue;

/**
 * 线程运行类
 *
 * @author ssk
 * @version 1.0
 * @date 2024/9/12 10:52
 */
public class MyRunnable implements Runnable {

    private String name;

    public MyRunnable(String name) {
        this.name = name;
    }

    static ConcurrentLinkedQueue<String> concurrentLinkedQueue;

    static {
        concurrentLinkedQueue = new ConcurrentLinkedQueue<>();
        for (int i = 1; i <= 10000000; i++) {
            concurrentLinkedQueue.offer(i + "");
        }
    }

    public void run() {
        // 必须要有run方法，并且将需要执行的任务放到run方法里
        while (!concurrentLinkedQueue.isEmpty()) {
            System.out.println(name + ": " + concurrentLinkedQueue.poll());
        }

//        for (int i = 1; i <= 5; i++) {
//            System.out.println(name + ": " + i);
//            try {
//                Thread.sleep(1000);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
//        }
    }
}