1

Trying to execute a thread in another core, i use java.util.concurrent.executor

I dont know if its enough to make the thread running in another core so, i want to know in witch core every thread is executed.

Any idea?

Executor executor = Executors.newSingleThreadExecutor();            
executor.execute(new Runnable() {       
             //some work
});
Nassim MOUALEK
  • 4,702
  • 4
  • 25
  • 44
  • 1
    I don't think you can know on which code a thread is run, and even less ensure it's run on another core. BTW, a thread can be executed on multiple cores. The OS scheduler should be smart enough to use the cores that are available. – JB Nizet Oct 26 '14 at 15:34
  • Since java 1.2, native thread has been replaced by green thread, so i dont think that the OS is respensible for the multi-core execution of the threads – Nassim MOUALEK Oct 26 '14 at 15:38
  • 2
    @NassimMOUALEK -- I'm pretty sure it's the other way around. Native threading replaced green threads in the JVM in around version 1.2 / 1.3. – Neil Oct 26 '14 at 15:43
  • 2
    Reference? You got this all wrong. It's the reverse. Green threads have been replaced by native threads. – JB Nizet Oct 26 '14 at 15:44
  • OK, thanks so you are telling me, that even if i Run a simple thread it has a chance to be executed in multi-cores?, without the java.lang.concurent.Executors – Nassim MOUALEK Oct 26 '14 at 15:48
  • 2
    Executors is just an abstraction layer above of threads. In the end, a thread is a thread. If a thread executes for one minute, this minute is actually sliced into small time slots, to let all the other threads on the system execute in parallel. Each time slot is potentially assigned to a different core. – JB Nizet Oct 26 '14 at 15:57

1 Answers1

1

This was discussed in more detail in this post: Java thread affinity

Some code popped out here.

The idea is to set affinity of the thread by making a native call through JNI and set the affinity from native code.

Community
  • 1
  • 1
VAndrei
  • 5,420
  • 18
  • 43