Results 1 to 6 of 6
- 07-01-2014, 07:55 PM #1
Enforcing different threads use different cores
Hi!
So I'm in the (planning) process of writing a program to read/write a fair amount of data to different HDDs. I figured I'd speed things up a bit by using different threads for each HDD (at least I'm assuming it'll speed things up, since it'd allow for multiple read/write operations at a time, rather than doing them one by one). Problem is, I can't find any way to lock a thread to a specific core... Is there a way to do that, or would it be better to just do the operations one at a time rather than taking the complicated path using threads (which will, obviously, require a fair amount of checks)?
- 07-01-2014, 08:42 PM #2
Re: Enforcing different threads use different cores
Why do you need to "lock a thread to a core"?
If you don't understand my response, don't ignore it, ask a question.
- 07-01-2014, 09:03 PM #3
Re: Enforcing different threads use different cores
Well, in this specific example, if two threads that both perform IO run on the same core, only one IO operation would take place at a time. By using two cores, I can use two IO operations at a time (assuming, of course, that they target different physical HDDs). Granted, the "twice the IO" is just a thought I'm having; I'm not sure if it'll even end up being the case.
I've also had the same issue in another piece of code I wrote, which was extremely processor intensive. Unfortunately though, despite using threads, most of the time the threads ended up on the same core, meaning only 50% of my CPU was actually used. On occasion the threads would end up on different cores making it 100%, but it was far from common enough to be even remotely reliable.
- 07-01-2014, 09:41 PM #4
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 15
Re: Enforcing different threads use different cores
I do not believe you can do that. In fact, it would be very un-Java like to provide that level of control over the processor. I would suspect it is done between some coordination between the JVM and the host OS. In fact, the JVM may be hostage to what the OS provides. But this is all speculation on my part.
Regards,
JimThe JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
- 07-01-2014, 09:54 PM #5
Re: Enforcing different threads use different cores
Long story short, this is completely up to the OS, not Java.
However, Java 7 did introduce the Fork/Join framework if you're especially curious: Fork/Join (The Java™ Tutorials > Essential Classes > Concurrency)How to Ask Questions the Smart Way
Static Void Games - GameDev tutorials, free Java and JavaScript hosting!
Static Void Games forum - Come say hello!
- 07-01-2014, 10:29 PM #6
Just a guy
- Join Date
- Jun 2013
- Location
- Netherlands
- Posts
- 5,114
- Rep Power
- 13
Re: Enforcing different threads use different cores
It is indeed one of those things you can't really control through Java. The best you can do is use Java 8 and its features which is very much optimized to let you run code in parallel and the JVM can do its best to work with the OS to offload the work as best as possible.
"Syntactic sugar causes cancer of the semicolon." -- Alan Perlis
Similar Threads
-
How to find no. of cores(Processors) by using java???
By piyushr999 in forum Advanced JavaReplies: 1Last Post: 01-17-2013, 06:11 PM -
Threads and cores
By aburnett397 in forum Threads and SynchronizationReplies: 1Last Post: 09-07-2011, 04:36 AM -
index enforcing query terms to appear within the same sentence
By miwieg in forum LuceneReplies: 0Last Post: 03-03-2011, 05:58 PM -
Running multiple threads on multiple CPU cores?
By Dosta in forum Threads and SynchronizationReplies: 2Last Post: 09-19-2010, 04:48 PM -
How to band threads with cup cores?
By young in forum Threads and SynchronizationReplies: 4Last Post: 04-06-2010, 02:39 PM
Bookmarks