IonOne
IonOne

Reputation: 385

Java : threads are limited to 25% of the CPU

when i use threads or the main thread, i noticed that they are limited to 25% of the CPU for each thread.

Is there a way to tell a thread to use more CPU ? because i find it a bit limitative that way.

thanks a lot.

Upvotes: 1

Views: 1359

Answers (2)

Narendra Pathai
Narendra Pathai

Reputation: 41935

public class Mainn {

    public static void main(String[] args) {
        int noOfProcessors = Runtime.getRuntime().availableProcessors();
        System.out.println(noOfProcessors);
        for (int i = 0; i< noOfProcessors ; i++){
            new Thread(new Runnable() {

                @Override
                public void run() {
                    for(;;){
                    }
                }
            }).start();
        }
    }
}

This would use a lot of CPU test it.

A thread or process would only use the amount of computation power required. you cannot tell it to take more computation power unless you create a code that requires more computation

One thread in JAVA can run on single core at a time. So all I have done is create a thread for each core.

Upvotes: 1

durron597
durron597

Reputation: 32323

You probably have a quad core machine. You can't have a thread run on more than one core.

Upvotes: 8

Related Questions