1

I have some java classes(blackbox) which I call through jni from native C code. There are 4 parallel threads in my native code which need to be running always and they call some java classes occasionally, but these classes run really slow. I am of the opinion that threads run on a single core and using multiple cores can solve my issue (crashing). I would like to run java environment in the background, the 4 native code threads on one core, and the java lasses if called should run on a separate core independent of the operations of the native code. Please tell me if I'm on the right track and let me know the possible way I can proceed.Thanks in advance.

Alok Kumar
  • 101
  • 2
  • 6
  • 1
    Why do you believe the threads are all running on a single core? The operating system automatically allocates threads to whichever processor cores are available to run them. Unless your other cores are all busy running *other* CPU-intensive programs, your threads should automatically run concurrently on multiple cores without any special effort on your part. – Wyzard Dec 15 '14 at 05:47
  • 1
    Also, you mentioned crashing as a problem you hope to solve by running on multiple cores. If a program crashes depending on how many cores it's using, that's a bug in the program itself. Giving it more cores isn't a solution, and doesn't guarantee that it won't crash (even if it makes it happen less often). The program itself needs to be fixed. – Wyzard Dec 15 '14 at 05:50
  • the two components were running well individually, and were later integrated to run simultaneously and this is the point when they run for a certain extent and then crash. Do you think running the 2 processes in parallel would do, maybe by using MPI?? – Alok Kumar Jan 13 '15 at 17:12
  • If your tasks are running in separate threads, they're probably running in parallel on different cores already; it's still unclear why you think they're not. But if they're not already running on different cores, making them do so isn't likely to stop the crashes. Running things in parallel tends to *create* problems, because of race conditions and inadequate locking of shared data. (This may be *why* your program is crashing with the tasks running in threads.) – Wyzard Jan 14 '15 at 07:03

1 Answers1

1

You cannot explicitly assign which core to execute your thread on,however you can assign priorities and affinities to threads.

A possible duplicate of this.

Community
  • 1
  • 1
abhati
  • 309
  • 1
  • 6