How many java threads can be created for a dual core processor
java, multithreading
Solution
You can run 20 threads even on a single-core machine. What happens is called time slicing.
http://en.wikipedia.org/wiki/Time_slice#Time_slice
It is a way for the processor to simulate multiple processors executing multiple tasks as once.
Problem
So the STB is dual core. I thought we can only create 2 proper threads. In every keyreleased() I am creating a new thread ``` Runnable runnable = new Runnable() { int i = j; public void run() { while (true) { System.out.println("This thread is running always number is " + i); } } }; Thread th = new Thread(runnable); th.setPriority(Thread.MAX_PRIORITY); th.start(); j++; //... } ``` But even after creating 20 more threads, box doesn't have any issues. Is it because JVM realized that the run block is empty and it optimized the code ? Or is the JVM implementation for while(true) is different ? Note: i have tried putting Thread.sleep(1000) as well but no problems