openmrs-core icon indicating copy to clipboard operation
openmrs-core copied to clipboard

TRUNK-6256: Draft moving threading to a single threadpool

Open ibacher opened this issue 1 year ago • 1 comments

Description of what I changed

Implements a class called OpenmrsThreadPoolHolder and moves the execution of all threads started in core to using that ThreadPool. Also adds convenience methods to the Daemon class supporting Futures. Most methods directly referencing Threads or DaemonThreads are deprecated.

Issue I worked on

see https://issues.openmrs.org/browse/TRUNK-6256

Checklist: I completed these to help reviewers :)

  • [x] My IDE is configured to follow the code style of this project.

    No? Unsure? -> configure your IDE, format the code and add the changes with git add . && git commit --amend

  • [x] I have added tests to cover my changes. (If you refactored existing code that was well tested you do not have to add tests)

    No? -> write tests and add them to this commit git add . && git commit --amend

  • [x] I ran mvn clean package right before creating this pull request and added all formatting changes to my commit.

    No? -> execute above command

  • [ ] All new and existing tests passed.

    No? -> figure out why and add the fix to your commit. It is your responsibility to make sure your code works.

  • [x] My pull request is based on the latest changes of the master branch.

    No? Unsure? -> execute command git pull --rebase upstream master

ibacher avatar Aug 12 '24 15:08 ibacher

Coverage Status

coverage: 64.718% (-0.1%) from 64.831% when pulling 4385cf19ad7373a2d5600531acaf21c9c52c3492 on TRUNK-6256 into d1aae84266a86df7b7dc8cc27ef826c6143bb6e8 on master.

coveralls avatar Aug 12 '24 20:08 coveralls

@ibacher do you happen to know, off head, why the changes in this pull request lead to the failure of DeamonTest.createUser_shouldCreateUserWithRolesInContextDAO when run on mysql? This is the command to run tests on mysql in a docker container: mvn test -DuseInMemoryDatabase=false -DtestDb=mysql

This is the error log: https://pastebin.com/cpaiNSf9

FWIW, the test passes when this method is reverted to what it was before the changes in the pull request: https://github.com/openmrs/openmrs-core/blob/master/api/src/main/java/org/openmrs/api/context/Daemon.java#L116-L153

dkayiwa avatar Oct 14 '24 20:10 dkayiwa

@dkayiwa Not really, but I suggested that @wikumChamith might try something similar to the code I explained here to see if that fixes things. I added it to resolve a race condition that showed up in the normal tests. (Short version: add a count-down latch with a value of 1 and call it's countDown() method only once the session is loaded; this will effectively block the calling thread until the context is established on the new thread which may resolve the issue).

ibacher avatar Oct 14 '24 21:10 ibacher