How to bind a thread to a CPU explicitly in Java

HI everyone,My question is how to bind a thread to a CPU explicitly in Java on Linux operating system. If anyone get the answer, please let me know. I appreciate it.yang
[190 byte] By [yang2007a] at [2007-11-27 7:51:48]
# 1
You can't bind a Thread to a specific CPU on your own using Java.
Dalzhima at 2007-7-12 19:32:59 > top of Java-index,Core,Core APIs...
# 2
Can u tell me why I can not do that? In my program, I need to assign thread to each CPU. Is there any way can do this? Thanks.
yang2007a at 2007-7-12 19:32:59 > top of Java-index,Core,Core APIs...
# 3
Because Dalzhim said so would be good enough reason for me.
bsampieria at 2007-7-12 19:32:59 > top of Java-index,Core,Core APIs...
# 4
But in C or C++, there is API to bind a thread to a specific CPU. Are u sure there is no such kind API in Java so far?
yang2007a at 2007-7-12 19:32:59 > top of Java-index,Core,Core APIs...
# 5

Yes I am sure there is no such API. There have been some RFEs (Requests for Enhancement) on this matter and as far as I know, none is to be implemented anytime soon.

Considering Java is meant to be portable and could very well run on single processor machines just like multi-processor ones, the details about which CPU a Thread is assigned to is better left to the JVM and it's Scheduler.

Dalzhima at 2007-7-12 19:32:59 > top of Java-index,Core,Core APIs...
# 6
> In my program, I> need to assign thread to each CPU. That's rather unlikely. You may think you do, but you're almost certainly mistaken.
jverda at 2007-7-12 19:32:59 > top of Java-index,Core,Core APIs...
# 7
> But in C or C++, there is API to bind a thread to a> specific CPU. Are u sure there is no such kind API in> Java so far?So... use RMI and the C/C++ API to do the work for you then?
bsampieria at 2007-7-12 19:32:59 > top of Java-index,Core,Core APIs...
# 8

> > But in C or C++, there is API to bind a thread to

> a

> > specific CPU. Are u sure there is no such kind API

> in

> > Java so far?

>

> So... use RMI and the C/C++ API to do the work for

> you then?

Er, JNI maybe?

jverda at 2007-7-12 19:32:59 > top of Java-index,Core,Core APIs...
# 9
I haven't been able to untangle all these crossposts, but has the OP everexplained *why* he wants to do this, other than it can be done in C?
Hippolytea at 2007-7-12 19:32:59 > top of Java-index,Core,Core APIs...
# 10

> > In my program, I

> > need to assign thread to each CPU.

>

> That's rather unlikely. You may think you do, but

> you're almost certainly mistaken.

I think you're wrong. I added the CPU from my broken toaster (don't ask) to my computer to take advantage the processing multi-core enablement. But as you may imagine, it's quite slower than PC processor. So it's useful for me to be able to specify that I want certain threads not to be running on my toaster. Let's call these ButterThreads (don't get butter in your toaster!).

Is there no way in Java to ensure code run only in toaster? This possible in C++, C.

oxbow_lakesa at 2007-7-12 19:32:59 > top of Java-index,Core,Core APIs...
# 11
> This possible in C++, C.Sorry, meant to specify. This what p-thread is. P means "pleases run in toaster".
oxbow_lakesa at 2007-7-12 19:32:59 > top of Java-index,Core,Core APIs...
# 12
Even though you're trying to re-use your toaster, the API still hasn't changed since my last reply.
Dalzhima at 2007-7-12 19:32:59 > top of Java-index,Core,Core APIs...
# 13

> Even though you're trying to re-use your toaster, the

> API still hasn't changed since my last reply.

I heard that there is new "curranty" API in the Tigers, Java 5 (or 1.5!!!!!) to use. This enable me do this? Is called curranty because there currants in hot cross buns, eccles cakes and soreen malt loaf? All uses in toasting I think, so maybe you get better knowledge of upto date APIs.

oxbow_lakesa at 2007-7-12 19:32:59 > top of Java-index,Core,Core APIs...