This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Repository navigation
Add delay in @Background #525
Merged
mathieuboniface
merged 4 commits into
androidannotations:develop
from
yDelouis:332_DelayInBackground
Apr 13, 2013
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
Use ScheduledExecutorService instead of Handler
- Loading branch information
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
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.
The core pool size set to
1, which AFAIK means the maximum number of threads on this executor will always 1. As a consequence, you'll never get two delayed tasks to run concurrently. Is that on purpose ?@Backgroundhas always had a parallel behavior, if we want serial behavior which should make a clear distinction.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.
I didn't know which value to set here. Maybe a big one (ex:
Integer.MAX_VALUE) or maybe we should create aScheduledExecutorServiceeach time we callexecuteDelayed? Do you know the effect of a value of0for the core pool size ? It's not said in the java doc and it doesn't seem to rise an exception.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.
It may be a good thing to let the user defines how many threads he wants because this is typically a parameter that changes according to the needs.
Maybe with another optional parameter in the
@Backgroundannotation. If the user doesn't fill this parameter, assign a default value to 5 for thecorePoolSize.What do you think about this idea?
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.
I don't think it's a good idea as it means each
@Backgroundcould be responsible of the creation of a thread pool. That could cause a performance issue, and it could be hard to understand from a developer point of view.I would prefer to define a value. Something like that :
What do you think ?
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.
I think Mathieu is right. The more so as a developper will be able to change the
ScheduledExecutorServiceusing the static method ofBackgroundExecutor. Regarding the value to set, I have no idea.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.
👍