Multi threaded game loop

No, you misunderstood me. The overhead can’t be avoided. Your message task is just so fast to compute that simply running the the task is faster than passing it to another thread. String manipulations involves lots of allocations that probably causes synchronization in the background. Try something simpler, like calculating the sum of all integers from 0 to N where N is 1 000 000 or even higher. Make sure you actually do something with the sum (I suggest simply printing the sum) or the compiler will just optimize it away. If your tasks are smaller than 1ms then you’re not gonna get very good scaling.

What about Math.sqrt()? Is that synchronized? I get similar results with that. :-\ I get what you’re saying, of course. I just wasn’t expecting such an overhead.

Edit: OH! Printing! I totally forgot about the fact that the jvm optimizes code like crazy! I will try that with something simple like you suggested, and have it run a bazillion times assuming that the range of a long is -bazillion to bazillion.

Edit2: We’re back to favorable results! Well, only when the task is cpu intensive, at least. Your printing suggestion seems to have worked.

Good job! ^^

You should not be allocating lots of new objects for a lot of reasons so benchmarking with them will not produce accurate results.

The functions in Math are thread safe.