-
Notifications
You must be signed in to change notification settings - Fork 317
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
Update QueueModerator.java #41
base: master
Are you sure you want to change the base?
Changes from 4 commits
cb91d02
9e46984
2de7e26
c02edba
b704fdd
4f3ca87
cbc26ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,36 +37,43 @@ public QueueModerator(TasksDataSource tasksDataSource, ChunksDataSource chunksDa | |
this.moderator = localModerator; | ||
this.moderator.setQueueObserver(this); | ||
this.listener = downloadManagerListener; | ||
this.downloadTaskPerTime = downloadPerTime; | ||
|
||
if (tasks.size() < downloadPerTime) { | ||
this.downloadTaskPerTime = tasks.size(); | ||
} else { | ||
this.downloadTaskPerTime = downloadPerTime; | ||
} | ||
this.uncompletedTasks = tasks; | ||
|
||
downloaderList = | ||
new HashMap<Integer, Thread>(downloadTaskPerTime); | ||
downloaderList =new HashMap<>(downloadTaskPerTime); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Revert There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. downloadTaskPerTime variable still final ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Alamusitl are you familiar with this library? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not much |
||
} | ||
|
||
|
||
public void startQueue() { | ||
|
||
if (uncompletedTasks != null) { | ||
|
||
int location = 0; | ||
while (uncompletedTasks.size() > 0 && | ||
!pauseFlag && | ||
downloadTaskPerTime >= downloaderList.size()) { | ||
Task task = uncompletedTasks.get(location); | ||
Thread downloader = | ||
new AsyncStartDownload(tasksDataSource, chunksDataSource, moderator, listener, task); | ||
|
||
downloaderList.put(task.id, downloader); | ||
uncompletedTasks.remove(location); | ||
|
||
downloader.start(); | ||
|
||
|
||
location++; | ||
} | ||
|
||
} | ||
if (uncompletedTasks != null) { | ||
|
||
int location = 0; | ||
while (uncompletedTasks.size() > 0 && | ||
!pauseFlag && | ||
downloadTaskPerTime >= downloaderList.size()) { | ||
try { | ||
Task task = uncompletedTasks.get(location); | ||
Thread downloader = | ||
new AsyncStartDownload(tasksDataSource, chunksDataSource, moderator, listener, task); | ||
|
||
downloaderList.put(task.id, downloader); | ||
uncompletedTasks.remove(location); | ||
|
||
downloader.start(); | ||
|
||
location++; | ||
} catch (IndexOutOfBoundsException e) { | ||
e.printStackTrace(); | ||
Log.e("QueueModerator", e.getMessage()); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public void wakeUp(int taskID){ | ||
|
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.
Maybe It's better to write something like this
But why?
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.
yes you have right, its better than my code