Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e9eccba

Browse files
committed
AJ-211 - Catching exception when executing a runnable with the configured thread pool executor fails
1 parent 96d2253 commit e9eccba

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/main/java/org/asteriskjava/fastagi/AbstractAgiServer.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,32 @@ protected void finalize() throws Throwable
119119
}
120120
}
121121

122+
/**
123+
* Execute the runnable using the configured ThreadPoolExecutor obtained from {@link #getPool()}.
124+
*
125+
* @param command the command to run.
126+
*/
122127
protected void execute(Runnable command)
123128
{
124129
if (isDie())
125130
{
126131
logger.warn("AgiServer is shutting down: Refused to execute AgiScript");
127132
return;
128133
}
129-
getPool().execute(command);
134+
135+
try
136+
{
137+
getPool().execute(command);
138+
}
139+
catch (Exception e)
140+
{
141+
handleException("Unable to execute " + command.getClass().getName(), e);
142+
}
143+
}
144+
145+
protected void handleException(String message, Exception e)
146+
{
147+
logger.warn(message, e);
130148
}
131149

132150
private synchronized ThreadPoolExecutor getPool()

src/main/java/org/asteriskjava/fastagi/DefaultAgiServer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,8 @@ public void startup() throws IOException, IllegalStateException
267267
}
268268
else
269269
{
270-
logger.error("IOException while waiting for connections.", e);
271-
// log error but continue
270+
handleException("IOException while waiting for connections.", e);
271+
// handle exception but continue to run
272272
}
273273
}
274274
}

0 commit comments

Comments
 (0)