views:

116

answers:

4

I have a game built in a java environment and I use JVM.

I have 4 cores @ 2.4Ghz and my server is only using one of those cores...

I've tried and searched and I still have no guides to setup multiple cores to run the game like, say 1 core for running the character saving + loading, and 1 core for the server itself, and 1 core for a helper to help other cores that need more power.

I don't even know if this is possible but this is all in java the operating machine is windows server 2003 and I've tried so hard I just don't know what to do.

May someone please help me!

Thank you so much!

+2  A: 

You cannot directly delegate tasks to specific CPU cores with Java, but if you implement your program using multiple threads (either directly or by using the executor utility classes in java.util.concurrent), the OS will run the different threads/tasks on different cores if it is possible.

To achieve this, you must of course understand the basics and pitfalls of multithreaded programming, learn how to exchange data safely between threads, prevent that several threads access and modify critical data simultaneously and so on. That topic however is far too broad to summarize here in a short answer.

jarnbjo
He built a game which is apparently designed to run in a single thread. Then you already can't do much at the server level, expect from running multiple instances of the same game but that's also not really what he's looking for.
BalusC
English is obviously not his first language (not mine either btw), but I read and understood his first sentence as if he had implemented a game in Java and now wants to know how to utilize multiple cores.
jarnbjo
That is great information thank you for posting this. Do you think you can further explain more to me about this critical data access? I was wanting t use that executor utility classes in java.util.concurrent to run a process on a core by itself for saving character accounts or creating new ones since that is pretty much the biggest part, then the other part would be having the server run on 1 core so lag would be bare to non to minimum.I do want to utilize multiple cores in my server.
Delta
+2  A: 

Java by default will take advantage of multiple cores. Unfortunately, an app must be specifically coded to be multithreaded. It's likely that the game is running everything in the Event Dispatch Thread. The application would need to be changed in order to take advantage of multiple cores.

On the bright side, processors like the Core i5 can detect when only a single core is being used, and can over-clock that single core. This helps programs which aren't or can't be multithreaded.

brianegge
A: 

One can also code multiple JVMs and each JVM can be bound to a set of CPUs, with the necessary RMI between them. This can be programming-related.

Xepoch
This is refered to a core *affinity*.
Nick Holt
Yes, some call it processor affinity, some CPU binding or bonding (read Linux kernel scheduler).
Xepoch
A: 

Some clarilty on that@Xepoch? I understand the RMI part, but how JVM can be bound to set of CPUs. Remember here I am talking about 4-core processors so thats 4 CPUs for me instead of 4 single-core processors.