-
Notifications
You must be signed in to change notification settings - Fork 14
Fix session perf. in synchronize/http req. context #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lalmeras
wants to merge
1
commit into
openwide-java:master
Choose a base branch
from
igloo-project:pr-session
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you start it in a new Thread if you need to wait for it here ? Why not just execute it in the current thread ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Synchronization process need to run in a separate Hibernate session for performance reason. Running it into a separate Thread and joining the thread is a way to run it with an isolated session without interrupting the HTTP thread&request-scoped session.
Another way to proceed would be to deal with Thread-scoped/TransactionSynchronizationManager registered session (save, replace, artifact synchronization, restore): it does not seem to me there is an helper for this ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You know better the details how this leads to better performance in your app, but this is how I see it from outside:
Wicket is thread-per-request based so if you use OpenSessionInViewFilter then you have one request scoped DB transaction. If you need to start a new one for the Maven sync then you can use
@Propagation.RequiresNewfor this service method. If you don't make it in a separate transaction then the only drawback I see is that the request-scoped transaction may get rolled back if something fails later.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are transaction-less at the time I do this trick (only session is opened at request scope, transaction are kept at service scope). This pattern is a bit original and can be tricky when rollbacks are involved, but work flawlessly for a lot of our projects.
I do not use @transactional mechanism as I do not want to wrap whole synchronization in a transaction (we deal with transaction around each artifact synchronization). I do not dig into @transactional configuration to see if it is possible to let it open a session without starting a new transaction.
As transactions are also separated (Thread trick also isolates transactions), there is no request-scoped transaction, and page / synchronization data do not need to be synced, I do not think there is any problem with transaction isolation / rollback.