Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
Openfire
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Openfire
Commits
2cf5afc9
Commit
2cf5afc9
authored
Jan 27, 2016
by
Dave Cridland
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #530 from tevans/OF-1063
OF-1063: Prevent TimerThread from exiting
parents
f999e759
ef7addfd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
6 deletions
+24
-6
TaskEngine.java
src/java/org/jivesoftware/util/TaskEngine.java
+24
-6
No files found.
src/java/org/jivesoftware/util/TaskEngine.java
View file @
2cf5afc9
...
...
@@ -23,7 +23,15 @@ import java.util.Date;
import
java.util.Map
;
import
java.util.Timer
;
import
java.util.TimerTask
;
import
java.util.concurrent.*
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.Future
;
import
java.util.concurrent.FutureTask
;
import
java.util.concurrent.ThreadFactory
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
* Performs tasks using worker threads. It also allows tasks to be scheduled to be
...
...
@@ -37,6 +45,7 @@ import java.util.concurrent.*;
*/
public
class
TaskEngine
{
private
static
final
Logger
Log
=
LoggerFactory
.
getLogger
(
TaskEngine
.
class
);
private
static
TaskEngine
instance
=
new
TaskEngine
();
/**
...
...
@@ -69,12 +78,16 @@ public class TaskEngine {
* @return a Future representing pending completion of the task,
* and whose <tt>get()</tt> method will return <tt>null</tt>
* upon completion.
* @throws java.util.concurrent.RejectedExecutionException if task cannot be scheduled
* for execution.
* @throws NullPointerException if task null.
*/
public
Future
<?>
submit
(
Runnable
task
)
{
return
executor
.
submit
(
task
);
try
{
return
executor
.
submit
(
task
);
}
catch
(
Throwable
t
)
{
Log
.
warn
(
"Failed to schedule task; will retry using caller's thread: {0}"
,
t
.
getMessage
());
FutureTask
<?>
result
=
new
FutureTask
<>(
task
,
null
);
result
.
run
();
return
result
;
}
}
/**
...
...
@@ -290,7 +303,12 @@ public class TaskEngine {
@Override
public
void
run
()
{
executor
.
submit
(
task
);
try
{
submit
(
task
);
}
catch
(
Throwable
t
)
{
// need to catch here to prevent Timer from canceling TimerThread
Log
.
error
(
"Failed to execute TimerTask"
,
t
);
}
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment