I made a runnable class and created a thread but with a unique name but when I send this thread though executor.scheduleAtFixedRate
it creates its own thread and I do not understand why is it?
I tried to read here but still, I do not understand this: https://www.codejava.net/java-core/concurrency/java-concurrency-scheduling-tasks-to-execute-after-a-given-delay-or-periodically
public class Main {
public static void main(String[] args) throws ClassNotFoundException {
ScheduledExecutorService executor =
Executors.newSingleThreadScheduledExecutor();
Runnable runnable = new AutoUpdater();
Thread thread = new Thread(runnable, "MyThread");
executor.scheduleAtFixedRate(thread, 0, 24, TimeUnit.HOURS);
}
}
public class AutoUpdater implements Runnable {
public void run() {
String threadName = Thread.currentThread().getName();
System.out.println(threadName + " is running...");
System.out.println("Thread ended.\n");
}
}
It should print the name MyThread but the output is:
pool-1-thread-1
and it should be maybe something like this :
pool-1-MyThread-1