Create a thread like this by creating a new Thread object.
public void my_method() { //тут делаю всякие свои действия //Создание потока Thread thr1 = new Thread(new Runnable() { @Override public void run() { //исполняемый код } }); //тут запускаю поток thr1.start(); } It is necessary to create many threads that will simultaneously solve the same task, but with different source data.
Those. You need to create threads from thr1 to thr100 . Copying streams in the source code and giving them names from 1 to 100 (and there may be more in the future) is clearly not an option.
We need to do something so that the name of the thread is created according to this principle:
i = i + 1 имя_потока = "thr"+i; Thread имя_потока = new Thread... ... But how to implement it in practice?
In this case, the flow is controlled from the same class, where it is created, and I would not want to lose this opportunity.
Alternatively, you can inherit from the class Thread , but then you need to create a thread in a separate class, which is very inconvenient in my situation. Or you can do without a separate class? But how?
public void run() { Thread.currentThread().setName("My custom name here"); }public void run() { Thread.currentThread().setName("My custom name here"); }...... I would also like to know why so many variables or naming is needed at all? For what? And would you like to use a pool of threads? - Alexey Shimansky