jetty-9 - Avoiding StackOverflowErrors when processing changes.

This commit is contained in:
Simone Bordet 2012-09-17 09:53:09 +02:00
parent 4f1a2990de
commit 4ea5734ab1
1 changed files with 22 additions and 5 deletions

View File

@ -53,6 +53,14 @@ import org.eclipse.jetty.util.log.Logger;
*/ */
public abstract class SelectorManager extends AbstractLifeCycle implements Dumpable public abstract class SelectorManager extends AbstractLifeCycle implements Dumpable
{ {
private static final ThreadLocal<Integer> _submissions = new ThreadLocal<Integer>()
{
@Override
protected Integer initialValue()
{
return 0;
}
};
protected static final Logger LOG = Log.getLogger(SelectorManager.class); protected static final Logger LOG = Log.getLogger(SelectorManager.class);
private final ManagedSelector[] _selectors; private final ManagedSelector[] _selectors;
@ -306,7 +314,8 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
*/ */
public boolean submit(Runnable change) public boolean submit(Runnable change)
{ {
if (Thread.currentThread() != _thread) int submissions = _submissions.get();
if (Thread.currentThread() != _thread || submissions >= 4)
{ {
_changes.offer(change); _changes.offer(change);
LOG.debug("Queued change {}", change); LOG.debug("Queued change {}", change);
@ -316,12 +325,20 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
return false; return false;
} }
else else
{
_submissions.set(submissions + 1);
try
{ {
LOG.debug("Submitted change {}", change); LOG.debug("Submitted change {}", change);
runChanges(); runChanges();
runChange(change); runChange(change);
return true; return true;
} }
finally
{
_submissions.set(submissions);
}
}
} }
private void runChanges() private void runChanges()