Issue
Ensure maximum CPU utilization. I know golang have a go expression like this, but java we can't ensure maximum CPU utilization. An unlimited number of threads consumes additional system resources
Solution
Your question is not clear. But I’ll take a guess: Future versions of Java may get the feature of virtual threads.
Virtual threads
I suspect you might be looking for the new virtual threads (fibers) feature being added as part of the Project Loom technology.
In today’s Java, Java threads are mapped onto host OS threads (“platform threads”), one to one. When the Java code in a thread blocks, such as waiting for storage I/O or network I/O, the thread blocks with no further work being done on that thread until the blocked code is able to continue.
In Loom, many virtual threads are mapped per platform thread. By “many”, I mean thousands, even millions — versus the dozens of threads commonly used nowadays.
When the code executing in a virtual thread blocks, the JVM “dismounts” that virtual thread so as to assign a different virtual thread to the “real” platform thread. This mounting and dismounting of virtual threads onto platform threads for execution is relatively very fast and efficient, with possibilities for even more speed in future versions of Loom technologies. So many apps will see dramatic improvements in performance and in workload throughput. And the CPU cores will get much more exercise.
To learn more, see the articles, interviews, and presentations by members of the Project Loom team, including Ron Pressler and Alan Bateman.
You asked:
Is there a FixedThreadPool can dynamicly suspend sleeping(or other waiting states) thread and running new task in JAVA?
See this new executor service.
ExecutorService es = Executors.newVirtualThreadPerTaskExecutor() ;
Answered By - Basil Bourque
Answer Checked By - Gilberto Lyons (JavaFixing Admin)