0

Thread in Java has a static method currrentThread(). Does that mean that only a single thread is going to run during a smallest time slice? That would be a bit counter-intuitive for me. Can someone clarify? Thanks.

xingbin
  • 27,410
  • 9
  • 53
  • 103
zell
  • 9,830
  • 10
  • 62
  • 115

1 Answers1

0

No.

The name "current thread" is an unfortunate historical artifact. It dates back to a time when computers had only one CPU. Its purpose is to return the ID of the thread that calls it. That is, it's the function that a thread can call to find its own ID.

Back in the day, it was easily implemented by simply returning the ID of the one thread that currently was running, because that was the only thread that could have called it.

Now that we have multi-processing systems, "current thread" is ambiguous because there could be four or sixteen or more than a hundred "current" threads. But the function always returns the ID of the thread that called it in any case.

Solomon Slow
  • 25,130
  • 5
  • 37
  • 57