Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8056947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:52:17+00:00 2026-06-05T08:52:17+00:00

I have a java process and a C++ process talking with each other over

  • 0

I have a java process and a C++ process talking with each other over a shared memory segment(using jni for java side communication). The code runs with decent speed if there is 1 thread in java and 1 in C++, but as soon as I use multiple threads in the processes the performance drops down a lot(almost 100x times).

After this I was tweaking a few things in the code (which I am running on my core2duo system) and found out that when I mapped the java process on one core say core0 and the cpp process on core1 (using sched_affinity()) the performance recovers back.

Why is this happening? I thought the problem could be cache contention over the shared memory segment but then, this core mapping improves the performance. Also the behavior is observed only if multiple threads are used. If single threads in both processes are used the speeds are normal.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T08:52:19+00:00Added an answer on June 5, 2026 at 8:52 am

    The “optimal” configuration when you have two threads running at full tilt is to have a core for each. If they aren’t moved around i e each thread stays on “its” core you’ll have better performance than if they are moved back and forth between the cores. So essentially a 2+2 thread solution will require 4 cores to run optimally.

    In addition since two cores are running the same code it is vital that they (in your case) aren’t moved from “their” core. This is because the operating environment for both cores is more or less the same which makes switching between them less cumbersome (at the cache level) than if you need to load everything onto a different core.

    Then you have the issue of memory system saturation. A “normal” single-threaded program will usually use up most if not all of the available memory bandwidth. Its speed will usually be determined by the rate at which the memory system provides it with data. There are exceptions such as when you’re in a division instruction during which no memory activity occurs or when you’re in a tight loop which doesn’t require data reads or writes. In most other cases the memory system will be working its butt off to shove memory into the program and a lot of the time not as fast as the program can make use of it.

    A program which doesn’t take this into account will run slower multi-threaded than single because both threads will start colliding when they need memory access and this slows things down a lot. This for compiled lanbguages such as C or C++. With Java there are a lot of memory accesses going on behind the scenes (caused by the engine) over which the programmer has little control. So the Java engine and its workings will use up a lot of the cache memory and bandwidth which will mean that your shared memory will be competing with the engine’s needs and be in and out of the cache more or less constantly.

    My two cents.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I already have Java code to display and process data from a database. I
I have a Java process which has been running for over a week. In
I have a Java process that opens a file using a FileReader. How can
I have a shell script that launches a Maven exec:java process - exec mvn
I have java script code to set some of the properties of ajax controls.
I have java source code in a text file. There has to be entered
In my source tree have Java code which is automatically generated from XSD files.
I have one java process starting another java process with JMX support enabled in
I have a Java process which is dying after running for a few days
I have a Java process that I run. If I start the process via

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.