@@ -22,30 +22,36 @@ public StandaloneTaskPriorityManager() {
22
22
private TaskManager taskManager ;
23
23
24
24
@ Override
25
- public void setTaskManager (TaskManager taskManager ) {
25
+ public final void setTaskManager (TaskManager taskManager ) {
26
26
this .taskManager = taskManager ;
27
27
}
28
28
29
29
@ Override
30
- public void add (Task <?, ?> task ) {
31
- synchronized (this ) {
32
- ready [task .priority ].addLast (task );
33
- if (nextPriority > task .priority ) nextPriority = task .priority ;
34
- this .notify ();
35
- }
30
+ public final synchronized void add (Task <?, ?> task ) {
31
+ ready [task .priority ].addLast (task );
32
+ if (nextPriority > task .priority ) nextPriority = task .priority ;
33
+ this .notify ();
36
34
}
37
35
38
36
@ Override
39
- public boolean remove (Task <?, ?> task ) {
40
- synchronized (this ) {
41
- return ready [task .priority ].removeInstance (task );
42
- }
37
+ public final synchronized boolean remove (Task <?, ?> task ) {
38
+ return ready [task .priority ].removeInstance (task );
43
39
}
44
40
45
41
@ Override
46
- public Task <?, ?> peekNextOrWait () {
42
+ public final Task <?, ?> peekNextOrWait () {
47
43
Task <?,?> t ;
48
44
do {
45
+ if (nextPriority < Task .PRIORITY_BACKGROUND ) {
46
+ t = ready [nextPriority ].pollFirst ();
47
+ if (t == null ) {
48
+ nextPriority ++;
49
+ continue ;
50
+ }
51
+ if (nextPriority < Task .PRIORITY_BACKGROUND && t .executeEvery <= 0 )
52
+ lastIdle = -1 ;
53
+ break ;
54
+ }
49
55
if (nextPriority == Task .NB_PRIORITES ) {
50
56
if (lastIdle < 0 )
51
57
lastIdle = System .currentTimeMillis ();
@@ -66,21 +72,19 @@ public boolean remove(Task<?, ?> task) {
66
72
}
67
73
return null ;
68
74
}
75
+ t = ready [Task .PRIORITY_BACKGROUND ].pollFirst ();
76
+ if (t == null ) {
77
+ nextPriority ++;
78
+ continue ;
79
+ }
80
+ break ;
69
81
}
70
- t = ready [nextPriority ].pollFirst ();
71
- if (t == null ) {
72
- nextPriority ++;
73
- continue ;
74
- }
75
- if (nextPriority < Task .PRIORITY_BACKGROUND && t .executeEvery <= 0 )
76
- lastIdle = -1 ;
77
- break ;
78
82
} while (true );
79
83
return t ;
80
84
}
81
85
82
86
@ Override
83
- public Task <?, ?> peekNext () {
87
+ public final Task <?, ?> peekNext () {
84
88
Task <?,?> t ;
85
89
do {
86
90
if (nextPriority == Task .NB_PRIORITES ) {
@@ -101,7 +105,7 @@ public boolean remove(Task<?, ?> task) {
101
105
}
102
106
103
107
@ Override
104
- public List <Task <?, ?>> removeAllPendingTasks () {
108
+ public final List <Task <?, ?>> removeAllPendingTasks () {
105
109
LinkedList <Task <?,?>> list = new LinkedList <>();
106
110
for (byte p = 0 ; p < Task .NB_PRIORITES ; ++p ) {
107
111
while (!ready [p ].isEmpty ())
@@ -111,7 +115,7 @@ public boolean remove(Task<?, ?> task) {
111
115
}
112
116
113
117
@ Override
114
- public void forceStop () {
118
+ public final void forceStop () {
115
119
nextPriority = Task .NB_PRIORITES ;
116
120
synchronized (ready ) {
117
121
ready .notifyAll ();
@@ -126,7 +130,7 @@ public void forceStop() {
126
130
}
127
131
128
132
@ Override
129
- public int getRemainingTasks (boolean includingBackground ) {
133
+ public final int getRemainingTasks (boolean includingBackground ) {
130
134
int nb = 0 ;
131
135
synchronized (this ) {
132
136
for (byte p = 0 ; p < Task .NB_PRIORITES ; ++p ) if (includingBackground || p != Task .PRIORITY_BACKGROUND ) nb += ready [p ].size ();
@@ -135,7 +139,7 @@ public int getRemainingTasks(boolean includingBackground) {
135
139
}
136
140
137
141
@ Override
138
- public boolean hasRemainingTasks (boolean includingBackground ) {
142
+ public final boolean hasRemainingTasks (boolean includingBackground ) {
139
143
synchronized (this ) {
140
144
for (byte p = 0 ; p < Task .NB_PRIORITES ; ++p )
141
145
if (includingBackground || p != Task .PRIORITY_BACKGROUND )
0 commit comments