В этом случае
sb.setLength(sb.length() - 1);
предпочтительнее, так как он просто присваивает последнее значение '\0'
, тогда как удаление последнего символа делает System.arraycopy
The Windows API functions to do this are SetProcessAffinityMask() and SetThreadAffinityMask(). I don't know .NET so I can't say whether there are wrappers around those functions, but this seems to suggest otherwise.
BTW: I agree that these are necessary only in very specific circumstances, it's normally best to let the OS scheduler deal with it. It's one of those questions where you probably shouldn't do it if you have to ask how.
This should free up one processor for you.
For doing it from the code you can add this statement:
System.Diagnostics.Process.GetCurrentProcess().ProcessorAffinity = (System.IntPtr) 1;
Cheers!
Actually, your application will not use more than one CPU unless you specifically do something to utilize more CPUs. If you use the thread pool and/or start additional threads you may use additional available cores, but otherwise your application will just have one thread per default and thus only use one CPU.