Answer the question
In order to leave comments, you need to log in
How to run multiple threads in JAVA?
Hello, there is a code:
Rst i1 = new Rst();
new Thread(i1).start();
Rst i2 = new Rst();
new Thread(i2).start();
Rst i3 = new Rst();
new Thread(i3).start();
int streaming = 3;
for(int i = 0; streaming >= i; i++) {
Rst i{#потока} = new Rst();
new Thread(i{#потока}).start();
}
Answer the question
In order to leave comments, you need to log in
In general, it's good practice to run many threads in a thread pool.
Here is a good introductory article on Habré.
Specifically, in your example, you can not create a variable, because. outside of the loop it doesn't make sense, then the code will look like this
int streaming = 3;
for(int i = 0; streaming <= i; i++) {
new Thread(new Rst()).start();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question