Hi,
Any ideas why we are constantly getting command scheduler loop overrun error after we switch to synchronized keyword in the code.
Thanks.
Hi,
Any ideas why we are constantly getting command scheduler loop overrun error after we switch to synchronized keyword in the code.
Thanks.
Iâm no expert on Java but I believe synchronized means only one place can access the method at a time? If thatâs the case, then maybe your code is having to wait for other parts of itself to finish before continuing an operation, slowing everything down and making your loop time greater than 20ms.
Can you post the full stack trace? Some more information is needed to see what is happening in your code
If youâre using Synchronized then I presume your code is multi-threaded? If so, then its possible that whatever other thread is accessing the Synchronized statements or methods is locking them for a long enough time that the main thread where the scheduler runs is having to wait too long to access that method. Synchronized statements do also incur an overhead so even if the statement/method isnât locked when you access it, the act of doing that lock/unlock adds time to your code execution and so if you are going through a bunch of Synchronized blocked/methods in a single scheduler run, it could potentially cause enough overhead to overrun the expected 20ms scheduler loop.
Best practice when it comes to accessing data between threads in a real-time system is to make the pieces of code that access/modify that data as short and fast as possible so that you arenât holding up threads that may also be looking to access that data regularly.
If you could share your code (preferably though GitHub) and talk about what youâre using the multi-threading for, we could definitely try to provide more tailored feedback and look for other potential causes/sources of the delay in your code.
694 was doing some testing with a profiler and traced it down to a specific function call in CommandScheduler, I made a PR that should ideally resolve this?
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.