ThreadClass function = new ThreadClass();
Given your comment, I think we can treat ThreadClass
as "almost the same" as Thread
here.
And then, your code creates a single thread object. On which you then call start()
many many times. Which is, simply not "valid" (see here for example).
So, from that point of view: your code creates a single thread, and then does something it shouldn't do.
Now, if you did:
for(int iThread = 0; iThread < 10000; iThread++) {
ThreadClass function = new ThreadClass();
function.start();
create one thread object per loop, then you would be creating 10K threads. What happens then ... very much depends. If all these threads stay alive, and do some real work, then most likely, you will either crash your machine, or some OS limitation will kick in and prevent your JVM from creating more threads than it ought to.
Assuming that your own class simply extends Thread, I would assume: you didn't overwrite the Thread run()
method. Therefore, all these threads will start, do nothing, and end. You create a lot of churn, but maybe, depending on OS and hardware, even the modified version that really creates 10K threads passes fine. It wouldn't do anything useful. Just the JVM asking the underlying OS to create a thread, invoke that, and then get rid of it soon thereafter.